Bird
0
0

What will be the output of this script?

medium📝 Predict Output Q13 of 15
Bash Scripting - Conditionals
What will be the output of this script?
#!/bin/bash
num=5
if [ $num -gt 10 ]; then
  echo "Greater than 10"
elif [ $num -eq 5 ]; then
  echo "Equals 5"
else
  echo "Less than 5"
fi
AEquals 5
BGreater than 10
CLess than 5
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check the value of num

    The variable num is set to 5.
  2. Step 2: Evaluate the conditions in order

    First condition checks if 5 > 10 (false), second checks if 5 == 5 (true), so it prints "Equals 5".
  3. Final Answer:

    Equals 5 -> Option A
  4. Quick Check:

    num=5 matches elif condition = A [OK]
Quick Trick: Check conditions top to bottom; first true runs [OK]
Common Mistakes:
MISTAKES
  • Assuming first condition is true
  • Ignoring elif branch
  • Confusing numeric comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes