Bird
0
0

What is wrong with this script snippet?

medium📝 Debug Q7 of 15
Bash Scripting - Error Handling
What is wrong with this script snippet?
command
if [ $? = 0 ]
 then
 echo "OK"
fi
AUsing single brackets instead of double brackets
BMissing semicolon after if condition
CUsing = instead of -eq for numeric comparison
DNot quoting the string "OK"
Step-by-Step Solution
Solution:
  1. Step 1: Understand test command syntax

    For numeric comparison in [ ], use -eq, not = which is for string comparison.
  2. Step 2: Identify error in condition

    Using = compares strings, so $? = 0 compares string values, which can cause unexpected results.
  3. Final Answer:

    Using = instead of -eq for numeric comparison -> Option C
  4. Quick Check:

    Numeric test uses -eq, not = [OK]
Quick Trick: Use -eq for numbers, = for strings in [ ] tests [OK]
Common Mistakes:
MISTAKES
  • Using = for numbers
  • Ignoring test syntax rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes