Bird
0
0

What will be the output of this script?

medium📝 Command Output Q4 of 15
Bash Scripting - Conditionals
What will be the output of this script?
#!/bin/bash
num=10
if [ $num -lt 5 ]; then
  echo "Less than 5"
elif [ $num -lt 15 ]; then
  echo "Less than 15"
else
  echo "15 or more"
fi
ALess than 15
B15 or more
CLess than 5
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the first condition

    Check if 10 is less than 5. It is false, so move to elif.
  2. Step 2: Evaluate the elif condition

    Check if 10 is less than 15. It is true, so print "Less than 15" and skip else.
  3. Final Answer:

    Less than 15 -> Option A
  4. Quick Check:

    Condition matches elif = C [OK]
Quick Trick: Check conditions top to bottom; first true runs [OK]
Common Mistakes:
MISTAKES
  • Assuming else runs if elif true
  • Misreading numeric comparisons
  • Forgetting to use -lt for numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes