Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A Linux administrator is writing a bash script that must exit immediately if any command fails. Which of the following should be included at the beginning of the script?

⚠ Common exam trap

XK0-006 often tests the confusion between `set -e` (exit on error), `set -u` (unset variable error), `set -x` (trace), and `pipefail` (pipeline exit status), so candidates must match the exact behavior described.

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` (errexit) causes the shell to exit immediately when any command returns a non-zero exit status, which is exactly the requirement for a script that must stop on the first failure. It is the standard idiom placed at the top of defensive bash scripts.

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 makes bash terminate the script immediately when any command returns a non-zero exit status, matching the requirement to abort on failure. Placed at the top, it governs all subsequent commands in the script.

  • ✗

    set -o pipefail

    Why it's wrong here

    set -o pipefail only changes a pipeline's exit status to reflect the rightmost failing command; alone it exits nothing. set -e must also be set for the script to terminate. pipefail is the right addition when pipelines must report failures accurately, but it does not by itself satisfy the immediate-exit requirement.

  • ✗

    set -u

    Why it's wrong here

    set -u errors on unset variable expansion, catching typos in variable names; it does not act on command exit statuses, so failures still pass unnoticed. set -e is the directive that exits immediately. Treating unset variables as fatal is valuable in defensive scripts, but it addresses variable hygiene, not command failure.

  • ✗

    set -x

    Why it's wrong here

    set -x enables command tracing to stderr; it changes no exit behaviour, so a failing command continues the script. set -e is what terminates execution on a non-zero status. Tracing is genuinely useful when debugging why a script misbehaves, which is why it appears plausible here, but it satisfies no failure-handling requirement.

About these practice questions

This XK0-006 question is part of Courseiva's 781-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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 CompTIA exam blueprint

This XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.