Courseiva
easyMultiple Choice

XK0-006 Practice Question: What does the `set -x` command do when placed at…

What does the `set -x` command do when placed at the top of a bash script?

⚠ Common exam trap

Test-takers frequently confuse `set -x` with `set -e` (exit on error) or `set -u` (treat unset variables as error), because all three are common debugging options but serve distinct purposes.

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

✓

Displays each command before executing it

`set -x` enables a shell debugging mode that prints each command (after expansion) to stderr before executing it. This is commonly used in bash scripts to trace execution flow and debug complex logic.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Enables position parameters

    Why it's wrong here

    Positional parameters are enabled by the shell itself, not by `set -x`; `set --` assigns them. The `-x` flag instead prints each command and its expanded arguments to stderr before execution, tracing script flow. The confusion arises because `set` manipulates many shell behaviours, and `set --` would be correct when resetting positional parameters.

  • ✗

    Exits the script on error

    Why it's wrong here

    set -x enables trace mode, printing each command and its expanded arguments to stderr before execution. It is tempting because set -e is the related option that exits on error, but -x only traces; the two flags are distinct and often combined.

  • ✗

    Treats unset variables as errors

    Why it's wrong here

    `set -e` treats unset variables as errors, not `set -x`. The `-x` flag prints each command and its expanded arguments to stderr before execution, aiding debugging of script flow. Confusing the two is easy because both are common `set` flags for hardening scripts, and `set -e` would be correct when a script must abort on any failure.

  • ✓

    Displays each command before executing it

    Why this is correct

    `set -x` enables the shell's trace mode, printing each command to standard error after expansion but before execution, prefixed with `+`. This satisfies the stem's requirement to reveal the actual expanded commands as the script runs, aiding debugging of variable substitution and quoting.

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.