XK0-006 Automation, Orchestration, and Scripting Practice Question
A Linux administrator writes a Bash script that processes a list of hostnames read from a file and must continue processing remaining hosts even if an SSH command to one host fails. The script currently uses set -e and exits on the first failure. Which change allows the loop to keep running while still exiting on other unhandled errors?
⚠ Common exam trap
The trap here is assuming set -e applies uniformly, when commands inside conditionals, AND-OR lists, or negations are exempt from triggering the 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
✓
Append || true to the SSH command inside the loop.
Bash's errexit option does not trigger on commands whose failure is consumed by a logical construct. Because the shell checks the exit status of the entire AND-OR list, appending || true to the SSH invocation means the list returns zero even when SSH fails, so the loop continues. Other commands in the script remain protected by set -e, preserving the desired fail-fast behavior elsewhere.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Append || true to the SSH command inside the loop.
Why this is correct
Under set -e, a command that is part of an OR list such as cmd || true is exempt from triggering exit, because the shell only aborts when the last command in the list returns non-zero. Appending || true lets the SSH failure be tolerated for that iteration while errexit still guards the rest of the script, which is precisely the requested behavior.
- ✗
Wrap the SSH command in a subshell with parentheses.
Why it's wrong here
A subshell inherits errexit, so a failing SSH inside ( ... ) still causes the subshell to exit with a non-zero status, and because the subshell itself is a simple command, the outer script also exits under set -e. The subshell adds process overhead without changing the failure semantics needed here, so the loop would still terminate early.
- ✗
Replace set -e with set +e globally.
Why it's wrong here
Disabling errexit entirely lets the script continue past every failure, including ones that should abort the run, such as a failed file read or a broken variable expansion. The requirement is to tolerate only the SSH failure inside the loop while still exiting on other unhandled errors, so a blanket set +e is too broad and removes the safety net.
- ✗
Redirect stderr to /dev/null on the SSH command.
Why it's wrong here
Suppressing error output hides diagnostic messages but does not change the exit status of the SSH command, so set -e still triggers and the script aborts. The administrator would lose useful troubleshooting information while the underlying early-exit problem remains completely unsolved, making this a cosmetic change rather than a behavioral fix.
Go deeper
Related to this question
Learn chapter
Logical Volume Management (LVM)
Key term
SSH
SSH (Secure Shell) is a cryptographic network protocol that provides secure, encrypted communication and remote administration between two devices over an unsecured network.
Key term
Shell
A shell is a computer program that provides a user interface to access an operating system's services, typically by accepting text commands.
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 →
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.