Bird
0
0

What will be the output of this bash script?

medium📝 Command Output Q4 of 15
Bash Scripting - Conditionals
What will be the output of this bash script?
num=15
if [ $num -gt 10 ]; then
  echo "Greater"
else
  echo "Smaller"
fi
AGreater
BSmaller
CNo output
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition [ $num -gt 10 ]

    Variable num is 15, which is greater than 10, so the condition is true.
  2. Step 2: Determine which branch runs

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

    Greater -> Option A
  4. Quick Check:

    15 -gt 10 is true, output = Greater [OK]
Quick Trick: If condition true, then branch runs [OK]
Common Mistakes:
MISTAKES
  • Confusing -gt with -lt
  • Forgetting to quote variables
  • Misreading the if-else structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes