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?
var=""
if [ -z "$var" ]; then
echo "Empty"
else
echo "Not Empty"
fi
ANot Empty
BEmpty
CSyntax Error
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the variable value

    The variable var is set to an empty string "".
  2. Step 2: Evaluate the -z test

    The test [ -z "$var" ] returns true if var is empty, so it will echo "Empty".
  3. Final Answer:

    Empty -> Option B
  4. Quick Check:

    Empty string test prints "Empty" [OK]
Quick Trick: -z returns true for empty strings [OK]
Common Mistakes:
MISTAKES
  • Not quoting variable causing errors
  • Confusing -z with -n
  • Expecting 'Not Empty' output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes