Bird
0
0

Find the error in this script snippet:

medium📝 Debug Q7 of 15
Bash Scripting - User Input
Find the error in this script snippet:
echo "Enter your choice:"
read choice
if [ $choice = "yes" ]; then
echo "Confirmed"
fi
ANo error, script runs correctly
BMissing quotes around $choice in test
Cif statement syntax is wrong
Dread cannot read into variable named choice
Step-by-Step Solution
Solution:
  1. Step 1: Check test condition syntax

    Variable $choice should be quoted to avoid errors if empty or spaces.
  2. Step 2: Identify potential error

    Without quotes, script may fail if input is empty or contains spaces.
  3. Final Answer:

    Missing quotes around $choice in test -> Option B
  4. Quick Check:

    Always quote variables in test conditions [OK]
Quick Trick: Quote variables in [ ] tests to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Not quoting variables in conditions
  • Thinking read variable name is invalid
  • Miswriting if statement syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes