Bird
0
0

What will be the output of this script snippet?

medium📝 Command Output Q13 of 15
Bash Scripting - Conditionals
What will be the output of this script snippet?
var=5
if [[ $var -gt 3 && $var -lt 10 ]]; then
echo "In range"
else
echo "Out of range"
fi
AIn range
BOut of range
CSyntax error
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate numeric conditions inside [[ ]]

    The variable var is 5. The condition checks if 5 is greater than 3 and less than 10, which is true.
  2. Step 2: Determine which branch runs

    Since the condition is true, the script echoes "In range".
  3. Final Answer:

    In range -> Option A
  4. Quick Check:

    5 > 3 and 5 < 10 = true [OK]
Quick Trick: Check each numeric condition carefully with && [OK]
Common Mistakes:
MISTAKES
  • Confusing -gt and -lt operators
  • Using single & instead of &&
  • Forgetting to quote variables (not critical here)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes