Bird
0
0

What will this script print?

medium📝 Command Output Q5 of 15
Bash Scripting - Conditionals
What will this script print?
#!/bin/bash
x=7
if [ $x -le 7 ]; then
echo "Yes"
fi
A7
BNo output
CYes
DError: missing fi
Step-by-Step Solution
Solution:
  1. Step 1: Check the condition [ $x -le 7 ]

    x=7, so 7 <= 7 is true.
  2. Step 2: Since condition is true, echo runs

    The script prints "Yes" because the condition is true and echo is inside the if block.
  3. Final Answer:

    Yes -> Option C
  4. Quick Check:

    True condition triggers echo output [OK]
Quick Trick: Use -le for less or equal comparison [OK]
Common Mistakes:
MISTAKES
  • Confusing -le with -lt
  • Forgetting fi to close if
  • Expecting output when condition false

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes