Courseiva

LPIC-1 Shells, Scripting and Data Management Practice Question

A shell script must exit immediately with a non-zero status if any command fails, and it must also treat an unset variable as an error. Which line should be placed at the top of the script?

⚠ Common exam trap

The trap here is assuming that -x and -u are interchangeable safety options, when -x only traces commands and provides no error handling at all.

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 -u

The fail-fast requirement maps to errexit (-e) and the unset-variable requirement maps to nounset (-u), so 'set -e -u' is the precise answer. Adding xtrace brings noisy tracing that was not asked for, and omitting either -e or -u leaves one requirement unmet. Short option letters and their long -o equivalents name the same behaviours, so the combined short form is the cleanest expression.

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 -u

    Why this is correct

    The -e option makes the shell exit as soon as a command returns non-zero, and -u makes referencing an unset variable an error that triggers that exit. Together they satisfy both stated requirements in a single line. This combination is the conventional safety header for scripts that must fail fast rather than continue with bad state.

  • ✗

    set -u -x

    Why it's wrong here

    The -u option does catch unset variables, but -x merely prints each command before execution. Without -e, a failing command does not terminate the script, so the fail-fast requirement is not satisfied. The script would continue after an error, potentially compounding damage, and only the unset-variable half of the requirement is covered.

  • ✗

    set -o errexit -o nounset -o xtrace

    Why it's wrong here

    errexit and nounset are the long forms of -e and -u and do cover both requirements, but adding xtrace enables tracing that was never requested. Verbose tracing clutters logs and can leak sensitive values from the environment into output, so this line over-delivers in a way that is operationally undesirable for a production script.

  • ✗

    set -e -x

    Why it's wrong here

    The -e option handles the fail-fast requirement, but -x only enables command tracing to standard error. Tracing is a debugging aid and does not treat unset variables as errors, so the second requirement is unmet. A script relying on this line would still silently expand an unset variable to an empty string and continue running.

About these practice questions

Courseiva writes every LPIC-1 question from scratch — 402 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 →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official LPI exam blueprint

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.