Bird
0
0

What happens when a command fails in a bash script with set -e enabled?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Error Handling
What happens when a command fails in a bash script with set -e enabled?
AThe script retries the command automatically.
BThe script ignores the error and continues.
CThe script immediately stops running.
DThe script logs the error but continues.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the effect of set -e

    The set -e option makes the script exit immediately if any command returns a non-zero status.
  2. Step 2: Apply this to command failure

    If a command fails (returns non-zero), the script stops running right away without executing further commands.
  3. Final Answer:

    The script immediately stops running. -> Option C
  4. Quick Check:

    Exit on error = Immediate stop [OK]
Quick Trick: set -e stops script on any command failure [OK]
Common Mistakes:
MISTAKES
  • Thinking script continues after error
  • Assuming automatic retries happen
  • Believing errors are just logged

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes