Bird
0
0

What will be the output of this script?

medium📝 Command Output Q13 of 15
Bash Scripting - Conditionals
What will be the output of this script?
#!/bin/bash
x=5
if [ $x -gt 3 ]; then
  echo "Greater"
else
  echo "Smaller"
fi
ANo output
BSmaller
CGreater
DSyntax Error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition

    The condition checks if x (5) is greater than 3, which is true.
  2. Step 2: Determine which branch runs

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

    Greater -> Option C
  4. Quick Check:

    5 > 3 = Greater [OK]
Quick Trick: Check numeric comparison carefully [OK]
Common Mistakes:
MISTAKES
  • Confusing -gt with -lt
  • Missing spaces causing syntax errors
  • Assuming else runs when condition is true

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes