LPIC-1 Shells, Scripting and Data Management Practice Question
A system administrator needs to ensure that a bash script continues executing even if any command in the script fails. Which of the following should be used at the beginning of the script?
⚠ Common exam trap
Many exam-takers confuse `set +e` with `set -e`, or think that a comment like `# set +e` would have any effect, when in fact the `+` sign disables the option and the `-` sign enables it.
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
✓
set +e
`set +e` disables the 'exit on error' behavior in a bash script, allowing the script to continue executing even if a command returns a non-zero exit status. By default, bash scripts do not exit on error, but if `set -e` is used elsewhere, `set +e` explicitly turns that off to ensure the script continues despite failures.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
set +e
Why this is correct
`set +e` disables the errexit behaviour, so bash continues running subsequent commands after any individual command returns a non-zero exit status. This directly satisfies the stem's requirement that the script keeps executing despite failures, since errexit is off by default but may have been enabled by a prior `set -e`.
- ✗
trap 'echo error' ERR
Why it's wrong here
trap with ERR runs a handler when a command fails but does not alter errexit behaviour; without set -e the script already continues, and with it the trap fires yet execution still aborts. It is tempting for error logging, which is its real purpose, not for controlling whether the script proceeds.
- ✗
unset -e
Why it's wrong here
unset -e removes the errexit option, but errexit is off by default in non-interactive shells, so this changes nothing in a script that never enabled it. It is tempting as the inverse of set -e, yet the stem's requirement is already the default unless set -e was applied earlier.
- ✗
set -e
Why it's wrong here
set -e does the opposite: it makes the shell exit immediately when any command returns non-zero, so the script stops rather than continues. It is tempting because it is the standard strict-mode idiom for failing fast, which suits scripts where aborting on error is the desired behaviour.
- ✗
# set +e
Why it's wrong here
The `+e` flag disables errexit, so the shell ignores failing commands and continues; the stem requires the opposite behaviour. It is tempting because `set +e` is the documented way to turn errexit off, which is correct when a script must tolerate individual command failures rather than abort.
Go deeper
Related to this question
About these practice questions
One of 402 original LPIC-1 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LPIC-1 practice question is part of Courseiva's free LPI 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 LPIC-1 exam.