Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A Linux administrator writes a bash script that needs to 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 difference between set -e (exit on error), set -u (error on unset variable), set -x (trace), and set -o pipefail (pipeline failure propagation) — candidates frequently pick pipefail thinking it alone causes script exit.

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 if any command returns a non-zero exit status, which is exactly the requirement. It is the standard way to make bash scripts fail fast rather than continuing after an error.

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

    Why it's wrong here

    set -x enables command tracing to stderr; it prints each command but does not alter exit behaviour, so execution continues after failures. It is tempting because it is the standard debugging aid when diagnosing why a script misbehaves, which is the correct choice when tracing execution rather than enforcing failure handling.

  • ✗

    set -u

    Why it's wrong here

    set -u aborts only on expansion of an unset variable; a command returning non-zero still leaves the script running. It is tempting because it is the correct safeguard when a script must not proceed with empty or misspelled variables, which is a different requirement from exiting on any command failure.

  • ✓

    set -e

    Why this is correct

    The set -e option instructs bash to terminate the script immediately when any command returns a non-zero exit status. Placing it at the top satisfies the requirement that the script halts on first failure rather than continuing with subsequent commands.

  • ✗

    set -o pipefail

    Why it's wrong here

    pipefail only changes a pipeline's exit status to reflect a failing component; it does not itself terminate the script on an ordinary failing command. It is tempting because it is genuinely needed when a pipeline's earlier stages fail silently, which is the correct addition alongside errexit for pipeline-heavy scripts.

About these practice questions

Courseiva writes every XK0-006 question from scratch — 781 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 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.