Courseiva
Shells, Scripting and Data ManagementmediumMultiple ChoiceObjective-mapped

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

    Disables exit on error, allowing the script to continue.

  • trap 'echo error' ERR

    Why it's wrong here

    Traps errors but does not prevent exit if set -e is active; also not the simplest method.

  • unset -e

    Why it's wrong here

    unset -e is not a valid command; -e is not a variable.

  • set -e

    Why it's wrong here

    This causes the script to exit on any error, opposite of desired.

  • # set +e

    Why it's wrong here

    A comment does not affect shell behavior.

About these practice questions

One of 527 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 →

How Courseiva writes practice questions · Editorial policy

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.