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=7
if [ $num -lt 10 ]; then
  echo "Small"
else
  echo "Big"
fi
ASmall
BBig
CError
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition $num -lt 10

    Variable num is 7, which is less than 10, so condition is true.
  2. Step 2: Determine which branch runs

    Since condition is true, the then branch runs, printing "Small".
  3. Final Answer:

    Small -> Option A
  4. Quick Check:

    Condition true prints then branch = B [OK]
Quick Trick: If condition true runs then branch [OK]
Common Mistakes:
MISTAKES
  • Confusing -lt with -gt
  • Ignoring variable value
  • Expecting else branch output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes