EX200 Create simple shell scripts Practice Question
An administrator writes a script that uses the 'set -e' option at the top. What is the primary effect of this option?
⚠ Common exam trap
Candidates often confuse 'set -e' with 'set -u' (unset variable errors) or with debugging options like 'set -x' or 'set -v', because all are shell options that begin with 'set -' but have very different effects.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
It exits the script immediately if a command fails
The 'set -e' option instructs the shell to exit immediately if any command or pipeline returns a non-zero exit status (i.e., fails). This is commonly used in scripts to prevent execution from continuing after an error, which could lead to unpredictable behavior or data corruption. It does not affect variable handling, command printing, or debug verbosity.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It treats unset variables as an error
Why it's wrong here
The behavior described belongs to `set -u` (nounset), which causes the shell to abort when expanding an unset variable. `set -e` (errexit) only monitors the exit status of commands; it has no effect on variable expansion. An unset variable error is a different class of failure and is not triggered by `set -e`.
- ✗
It prints each command before execution
Why it's wrong here
Printing each command before execution is the job of `set -x` (xtrace), which expands commands and displays them on standard error with `PS4` as prefix. `set -e` does not generate any command tracing output; it changes the script's control flow by exiting on non-zero status. The xtrace option is for debugging, not for error handling.
- ✗
It enables debug mode with verbose output
Why it's wrong here
Debug mode with verbose output is enabled by `set -v` (verbose) which echoes input lines as read, or by `set -x` for executed commands. `set -e` is strictly an error-exit switch, not a debug facility. It does not produce diagnostic output; it only causes an immediate exit upon a failing command, which is unrelated to enabling tracing or verbose mode.
- ✓
It exits the script immediately if a command fails
Why this is correct
This is the exact purpose of `set -e`, also known as `errexit`. When enabled, the shell immediately exits if any simple command, pipeline, or compound command (outside of contexts like `if`, `while`, `until`, `!`, or `&&`/`||` left operands) returns a non-zero status. This halts the script at the first error rather than continuing with unchecked failures.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX200 question from scratch — 127 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This EX200 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX200 exam.