Bird
0
0

What does the set -e command do in a bash script?

easy🧠 Conceptual Q11 of 15
Bash Scripting - Error Handling
What does the set -e command do in a bash script?
AIt stops the script immediately if any command returns a non-zero exit status.
BIt prints all commands before executing them.
CIt ignores errors and continues running the script.
DIt runs the script in debug mode.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of set -e

    The set -e option tells bash to exit the script if any command fails (returns a non-zero status).
  2. Step 2: Compare with other options

    Options like printing commands or ignoring errors do not match set -e's behavior.
  3. Final Answer:

    It stops the script immediately if any command returns a non-zero exit status. -> Option A
  4. Quick Check:

    set -e = exit on error [OK]
Quick Trick: Remember: set -e means exit on any error [OK]
Common Mistakes:
MISTAKES
  • Confusing set -e with set -x (debug mode)
  • Thinking it ignores errors instead of stopping
  • Assuming it prints commands before running

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes