Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A Bash script contains the following line: set -e. What is the effect of this command?

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

✓

It causes the script to exit if any command fails.

set -e causes the script to exit immediately if any command exits with a non-zero status. This is useful for catching errors early.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    It enables debugging by printing commands and their arguments as they are executed.

    Why it's wrong here

    Debugging output comes from set -x, which prints each command with expanded arguments before execution. set -e instead exits the shell immediately when any command returns a non-zero status. The confusion arises because both flags are commonly added together during troubleshooting, so set -x is the flag that actually produces the trace this option describes.

  • ✗

    It prevents the script from overwriting existing files.

    Why it's wrong here

    Overwrite protection is controlled by noclobber (set -C), which makes redirection fail when the target file already exists. set -e performs no file handling at all; it only terminates the script on a failing command's non-zero exit status. The tempting link is that both flags guard against unwanted outcomes, but noclobber is the correct choice for protecting existing files.

  • ✓

    It causes the script to exit if any command fails.

    Why this is correct

    The set -e option sets errexit, so Bash terminates the script immediately when any command returns a non-zero exit status. This satisfies the requirement to halt execution on failure rather than continuing through subsequent commands.

  • ✗

    It treats unset variables as an error and exits.

    Why it's wrong here

    Treating unset variables as errors is the job of set -u (nounset), which aborts expansion of an undefined variable. set -e instead acts on command exit statuses, exiting when any command fails. The two are frequently enabled together in strict-mode scripts, which is why set -u is mistaken for set -e here.

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 →

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.