XK0-006 Automation, Orchestration, and Scripting Practice Question
A Linux administrator maintains a Bash deployment script that runs unattended from cron. The script currently contains `set -e` and `set -u`, but it silently continues past a failing command inside a pipeline such as `tar -czf backup.tgz /srv | tee /var/log/backup.log`. The administrator wants the script to abort whenever any element of that pipeline returns a non-zero status. Which line should be added to the top of the script?
⚠ Common exam trap
The trap here is assuming that set -e alone covers every failure, when it ignores all but the final command's status in a pipeline unless pipefail is also enabled.
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 -o pipefail
Pipelines report only the last command's status by default, so a failing producer such as tar can be masked by a succeeding consumer such as tee. Enabling pipefail makes the pipeline return the first non-zero status encountered, which combines with set -e to abort the unattended script immediately. This preserves the existing error-handling design while closing the pipeline gap.
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 -v
Why it's wrong here
set -v echoes shell input lines as they are read, which is useful for verifying parsing of complex quoting but has no effect on pipeline exit codes. The tar failure would still be hidden behind tee's zero status, so the script continues past a broken backup. It does not provide the abort-on-failure semantics the administrator needs.
- ✗
set -x
Why it's wrong here
set -x turns on command tracing, printing each expanded command to stderr before execution. It is a debugging aid and does not change exit-status evaluation, so the pipeline would still report tee's success and the script would keep running. It adds noise to the cron mail output without fixing the silent-failure behavior described.
- ✗
set -n
Why it's wrong here
set -n performs a syntax check by reading commands without executing them. Adding it would prevent the entire script body from running, which is the opposite of the goal. It is occasionally used with bash -n to validate a script before deployment, but it never influences pipeline exit-status handling.
- ✓
set -o pipefail
Why this is correct
With pipefail enabled, the exit status of a pipeline becomes the rightmost non-zero status of any command in it, so a failure in tar propagates and set -e terminates the script. This directly addresses the scenario where the pipeline's final command (tee) succeeds and masks the earlier failure, keeping unattended cron runs from continuing on corrupt backups.
Go deeper
Related to this question
Learn chapter
Installing Linux and Package Management
Key term
cron
Cron is a time-based job scheduler in Unix-like operating systems that automatically runs commands or scripts at specified dates and times.
Key term
Bash
Bash is a command-line interpreter that lets users interact with an operating system by typing text commands instead of clicking icons.
About these practice questions
One of 781 original XK0-006 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 →
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.