Bird
0
0

Identify the problem in this script:

medium📝 Debug Q7 of 15
Bash Scripting - Conditionals
Identify the problem in this script:
#!/bin/bash
if [ $num -gt 10 ]; then
  echo "Big"
else
  echo "Small"
fi
AVariable $num is not quoted, may cause errors if empty
BMissing then keyword
CWrong comparison operator
Dfi is missing
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage in condition

    Variable $num is unquoted. If empty, test fails with error.
  2. Step 2: Verify other syntax parts

    then and fi are present and operator -gt is correct.
  3. Final Answer:

    Variable $num is not quoted, may cause errors if empty -> Option A
  4. Quick Check:

    Quote variables in tests to avoid errors = C [OK]
Quick Trick: Always quote variables in conditions [OK]
Common Mistakes:
MISTAKES
  • Leaving variables unquoted
  • Forgetting then or fi
  • Using wrong operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes