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 your age: age
 echo "You are $age years old."
AThe <code>read</code> command cannot use <code>-p</code>.
BMissing quotes around the prompt message.
CThe echo command syntax is wrong.
DVariable name cannot be <code>age</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Check the read -p syntax

    The prompt message after -p must be enclosed in quotes to be treated as a single string.
  2. Step 2: Identify the missing quotes

    The script has read -p Enter your age: age without quotes around "Enter your age:", causing a syntax error.
  3. Final Answer:

    Missing quotes around the prompt message. -> Option B
  4. Quick Check:

    Prompt message needs quotes [OK]
Quick Trick: Always quote prompt text after -p [OK]
Common Mistakes:
MISTAKES
  • Not quoting prompt text with spaces
  • Thinking variable names are restricted
  • Misreading echo syntax as error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes