Bird
0
0

Consider this script with set -e enabled:

medium📝 Command Output Q13 of 15
Bash Scripting - Error Handling
Consider this script with set -e enabled:
#!/bin/bash
set -e
echo "Start"
false
echo "End"
What will be the output when this script runs?
AStart End
BNo output
CEnd
DStart
Step-by-Step Solution
Solution:
  1. Step 1: Analyze script commands with set -e

    The script prints "Start", then runs false which returns a non-zero exit status causing the script to exit immediately.
  2. Step 2: Determine which commands run

    Because of set -e, the script stops after false, so "End" is never printed.
  3. Final Answer:

    Start -> Option D
  4. Quick Check:

    set -e stops script on error, so only "Start" prints [OK]
Quick Trick: Script stops at first error, so later lines don't run [OK]
Common Mistakes:
MISTAKES
  • Expecting all echo statements to run
  • Ignoring that false returns error
  • Thinking set -e allows script to continue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes