XK0-006 Automation, Orchestration, and Scripting Practice Question
A Linux administrator needs to write a Bash script that runs a series of commands and stops immediately if any command fails. Which directive should be included at the beginning of the script?
⚠ Common exam trap
The trap is confusing set -e (exit on error) with set -x (trace commands) or with trap ERR (custom error handler) — candidates must remember that only set -e provides the immediate-exit behavior the question requires.
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 set -e directive (also written set -o errexit) instructs Bash to exit immediately if any command returns a non-zero exit status. Placing it at the top of a script ensures the script halts on the first failure rather than continuing with potentially harmful subsequent commands. This is the standard idiom for fail-fast 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.
- ✗
#!/bin/bash
Why it's wrong here
The shebang only selects the interpreter that executes the script; it sets no failure behaviour, so later commands continue after an error. It is tempting because every Bash script legitimately begins with it, and it is required whenever the script must run under Bash rather than the caller's shell.
- ✗
trap ... ERR
Why it's wrong here
A trap on ERR runs a handler when a command fails but does not itself abort the script; execution continues unless the handler explicitly exits. It tempts because ERR traps genuinely suit logging, cleanup or alerting on failure, which is a different requirement from halting the run.
- ✓
set -e
Why this is correct
set -e makes Bash exit immediately when any command returns a non-zero status, so the script halts on the first failure. Placed at the top, it satisfies the requirement to stop immediately rather than continue executing subsequent commands.
- ✗
set -x
Why it's wrong here
set -x enables command tracing to stderr for debugging; it changes no exit behaviour, so failures pass unnoticed. It is tempting because tracing genuinely helps diagnose why a script misbehaves, and administrators commonly add it during troubleshooting rather than for fail-fast control flow.
Go deeper
Related to this question
Learn chapter
Linux Fundamentals and History
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.
Key term
Bash script
A Bash script is a text file containing a sequence of commands for the Unix shell Bash, allowing users to automate repetitive tasks and streamline system administration on Linux and macOS.
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.