Bird
0
0

Identify the error in this bash conditional snippet:

medium📝 Debug Q14 of 15
Bash Scripting - Conditionals
Identify the error in this bash conditional snippet:
if [ $value = 10 ]; then
  echo "Value is 10"
fi
AMissing semicolon before then
BUsing single equals for numeric comparison
CBrackets should be double [[ ]]
DNo error, script runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Understand comparison operators in bash

    For numeric comparison inside [ ], use -eq instead of =.
  2. Step 2: Check the snippet

    The snippet uses = which is for string comparison, so numeric comparison is incorrect here.
  3. Final Answer:

    Using single equals for numeric comparison -> Option B
  4. Quick Check:

    Numeric compare needs -eq not = [OK]
Quick Trick: Use -eq for numbers, = for strings in [ ] [OK]
Common Mistakes:
MISTAKES
  • Confusing string and numeric operators
  • Thinking = works for numbers
  • Ignoring bash operator rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes