Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q14 of 15
Bash Scripting - User Input
Identify the error in this script snippet:
read -p "Enter password:" password -s
echo "Password is $password"
AThe prompt string is missing quotes.
BThe <code>-s</code> option is placed after the variable name.
CThe variable name should be before options.
DThere is no error; the script works fine.
Step-by-Step Solution
Solution:
  1. Step 1: Check option placement in read

    Options like -s must come before the variable name; here it is after.
  2. 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.
  3. Final Answer:

    The -s option is placed after the variable name. -> Option B
  4. Quick Check:

    Options after variable = treated as names [OK]
Quick Trick: Put all options before variable name to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Placing options after variable name
  • Assuming the script hides input correctly
  • Assuming prompt needs no quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes