Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A Linux administrator is writing a Bash script that must continue running even if an unset variable is referenced, but must still abort on a failed command. Currently the script has only `#!/bin/bash` at the top. Which line should be added to meet these requirements?

⚠ Common exam trap

The trap here is assuming that any `set` option that influences error handling will also make the script exit on a failed command.

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

The requirement is to abort on a failed command while still tolerating references to unset variables. `set -e` provides the abort-on-error behavior, and because `-u` is not enabled, unset variables do not trigger termination. Enabling trace output or altering pipeline exit status does not produce the requested failure semantics, and enabling unset-variable errors would do the opposite of what is required.

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 trace output, printing each command and its expanded arguments to stderr before execution. It is a debugging aid only and does not change exit behavior for failed commands or unset variables. The script would still continue after a failed command, so it does not meet the requirement to abort on failure.

  • ✗

    set -u

    Why it's wrong here

    Adding `set -u` makes the shell treat references to unset variables as an error and exit, which is the exact opposite of continuing when an unset variable is referenced. It also does nothing to make the script abort on a failed command, so it fails both requirements of this scenario and would introduce premature termination.

  • ✗

    set -o pipefail

    Why it's wrong here

    `set -o pipefail` changes the exit status of a pipeline to reflect the last non-zero command within it, but by itself it does not cause the script to exit on failure; that requires `set -e`. It also has no effect on unset variable handling, so it fails to satisfy the abort-on-failed-command requirement in this scenario.

  • ✓

    set -e

    Why this is correct

    `set -e` causes the shell to exit immediately when a command returns a non-zero status, satisfying the requirement to abort on failed commands. Because `-u` is not included, referencing an unset variable does not terminate the script, so the script continues running. This combination precisely matches the administrator's stated requirements.

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.