Courseiva
mediumMultiple Select

XK0-006 Practice Question: A Linux engineer needs to ensure a bash script…

A Linux engineer needs to ensure a bash script runs with strict error handling. Which TWO of the following should be included? (Choose two.)

⚠ Common exam trap

CompTIA often tests the distinction between debugging options (set -x) and error-handling options (set -e, set -o pipefail), leading candidates to mistakenly choose set -x as a strict error-handling mechanism.

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

Option A (set -o pipefail) is correct because it makes a pipeline return the exit status of the last command that failed rather than only the final command's status, so errors in any stage of a pipe are caught under strict error handling. Option C (set -e) is correct because it causes the shell to exit immediately when any command returns a non-zero status, which is the core of strict error handling in bash scripts. Together, set -e and set -o pipefail ensure failures are not silently ignored, which is the standard strict-mode combination. Option B (set -n) only reads commands without executing them (syntax check), so it does not enforce error handling. Option D (set -x) merely prints commands as they execute for debugging and does not stop on errors. Option E (shopt -s histappend) only appends history to the history file instead of overwriting it, which is unrelated to script error handling.

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 -o pipefail

    Why this is correct

    set -o pipefail makes a pipeline return the rightmost non-zero exit status, so failures in earlier commands are not masked by a succeeding final command. This enforces strict error handling across pipelines, which set -e alone cannot detect.

  • ✗

    set -n

    Why it's wrong here

    set -n reads commands without executing them, performing only syntax checking; the script never runs, so no error handling occurs. It is tempting because it is a valid shell option used to validate script syntax before deployment, but strict error handling requires set -e, -u and -o pipefail during real execution.

  • ✓

    set -e

    Why this is correct

    `set -e` makes bash exit immediately when any command returns a non-zero status, satisfying the strict error-handling requirement. Without it, a failing command is silently ignored and the script continues, masking faults. Combined with `set -u` or `set -o pipefail`, it forms the standard strict-mode preamble for reliable automation scripts.

  • ✗

    set -x

    Why it's wrong here

    set -x enables trace output, printing each command before execution; it changes no exit or error semantics, so scripts continue past failures. It is tempting because it is a diagnostic aid for debugging scripts, but strict error handling needs set -e, -u and -o pipefail to actually halt on errors.

  • ✗

    shopt -s histappend

    Why it's wrong here

    histappend only controls whether history is appended rather than overwritten when a shell exits; it has no effect on error handling. It is tempting because shopt options configure shell behaviour, but strict mode requires set -e, -u and -o pipefail, which abort or fail on errors, unset variables and pipeline failures.

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 →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.