A. The prompt appears, input is visible, then prints 'You entered: [input]'.
B. The prompt does not appear, input is visible, then prints 'You entered: [input]'.
C. The script throws a syntax error.
D. The prompt 'Enter secret: ' appears, input is hidden, then prints 'You entered: [input]'.
Solution
Step 1: Analyze the read -s -p behavior
The prompt string is shown, but the input typed is hidden (silent).
Step 2: Understand the echo output
After input, the script prints the entered value with the message.
Final Answer:
The prompt 'Enter secret: ' appears, input is hidden, then prints 'You entered: [input]'. -> Option D
Quick Check:
read -s -p shows prompt, hides input [OK]
Hint: Prompt shows, input hidden, echo prints input [OK]
Common Mistakes:
Assuming input is visible with -s
Thinking prompt won't show
Expecting syntax error
4. Identify the error in this script snippet:
read -p "Enter password:" password -s
echo "Password is $password"
medium
A. The prompt string is missing quotes.
B. The -s option is placed after the variable name.
C. The variable name should be before options.
D. There is no error; the script works fine.
Solution
Step 1: Check option placement in read
Options like -s must come before the variable name; here it is after.
Step 2: Understand the consequences
Placing -s after the variable name treats it as another variable name instead of an option, so input is not hidden.
Final Answer:
The -s option is placed after the variable name. -> Option B
Quick Check:
Options after variable = treated as names [OK]
Hint: Put all options before variable name to avoid errors [OK]
Common Mistakes:
Placing options after variable name
Assuming the script hides input correctly
Assuming prompt needs no quotes
5. You want to create a bash script that asks the user for a password silently, then confirms the password by asking again silently. Which script snippet correctly implements this?
hard
A. read -s -p "Enter password: " pass
read -s -p "Confirm password: " pass2
if [[ "$pass" == "$pass2" ]]; then echo "Passwords match"; else echo "Mismatch"; fi
B. read -p "Enter password: " -s pass
read -p "Confirm password: " -s pass2
if [ $pass = $pass2 ]; then echo "Passwords match"; else echo "Mismatch"; fi
C. read -s pass "Enter password: "
read -s pass2 "Confirm password: "
if [[ $pass == $pass2 ]]; then echo "Passwords match"; else echo "Mismatch"; fi
D. read pass -s -p "Enter password: "
read pass2 -s -p "Confirm password: "
if [[ "$pass" = "$pass2" ]]; then echo "Passwords match"; else echo "Mismatch"; fi
Solution
Step 1: Verify correct syntax for silent input with prompt
The read -s -p "Enter password: " pass
read -s -p "Confirm password: " pass2
if [[ "$pass" == "$pass2" ]]; then echo "Passwords match"; else echo "Mismatch"; fi uses read -s -p "prompt" variable correctly for both inputs.
Step 2: Check password comparison syntax
The read -s -p "Enter password: " pass
read -s -p "Confirm password: " pass2
if [[ "$pass" == "$pass2" ]]; then echo "Passwords match"; else echo "Mismatch"; fi uses double brackets and quotes around variables, which is safe and correct for string comparison.
Final Answer:
read -s -p "Enter password: " pass
read -s -p "Confirm password: " pass2
if [[ "$pass" == "$pass2" ]]; then echo "Passwords match"; else echo "Mismatch"; fi -> Option A
Quick Check:
Correct option order and safe comparison = read -s -p "Enter password: " pass
read -s -p "Confirm password: " pass2
if [[ "$pass" == "$pass2" ]]; then echo "Passwords match"; else echo "Mismatch"; fi [OK]
Hint: Use read -s -p and double brackets with quotes for comparison [OK]
Common Mistakes:
Placing options after variable name
Using single brackets without quotes for strings
Incorrect order of arguments in read
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.