XK0-006 Automation, Orchestration, and Scripting Practice Question
A DevOps engineer needs to debug a bash script that unexpectedly fails when processing files. Which of the following should be added to the script to print each command before execution?
⚠ Common exam trap
XK0-006 often tests the distinction between set -x (trace executed commands) and set -v (echo input lines) — candidates pick -v thinking it shows execution, but only -x shows expanded commands as they run.
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 -x
set -x enables shell tracing, which prints each command (with expanded variables) to stderr prefixed by PS4 (usually '+') before execution. This is exactly what is needed to see what the script is doing as it processes files and where it fails.
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, showing raw script text rather than each command after expansion. It is tempting because it does print lines, but set -x is the mode that traces executed commands with their expanded arguments.
- ✗
set -e
Why it's wrong here
set -e exits immediately when any command returns a non-zero status, so the script stops rather than revealing the failing sequence. It is tempting because it surfaces failures early, but it suppresses the command-by-command trace the engineer needs to locate the fault.
- ✓
set -x
Why this is correct
`set -x` enables the shell's trace mode, printing each command to stderr after expansion but before execution, prefixed with `+`. This satisfies the stem's requirement to display every command as it runs, letting the engineer follow the script's actual execution path and pinpoint where file processing fails.
- ✗
set -u
Why it's wrong here
set -u aborts the script when an unset variable is referenced, catching typos but printing nothing about command execution. It is tempting as a defensive scripting habit, yet the requirement is tracing each command before it runs, which set -x provides.
Go deeper
Related to this question
Learn chapter
Basic Shell Scripting
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.