Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A Bash script contains the following code: if [[ $# -eq 0 ]]; then echo 'No arguments'; fi. What does this code check?

⚠ Common exam trap

The trap is confusing $# (argument count) with $1 (first argument) or $? (exit status); candidates must memorize that $# specifically returns the number of positional parameters.

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

✓

Whether the script was called with no arguments

In Bash, $# is a special parameter that expands to the number of positional parameters (arguments) passed to the script. The test [[ $# -eq 0 ]] evaluates to true when zero arguments were supplied, so the script echoes 'No arguments' when called without any arguments.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Whether the first argument is empty

    Why it's wrong here

    $# is the argument count, not the content of $1, so an empty first argument still yields $# equal to one. Testing whether the first argument is empty requires [[ -z $1 ]], the form used when validating a supplied value rather than detecting missing arguments.

  • ✓

    Whether the script was called with no arguments

    Why this is correct

    The `$#` variable holds the argument count passed to the script, and `-eq 0` tests whether it equals zero. When no arguments are supplied, the condition succeeds and prints 'No arguments', directly satisfying the scenario's requirement to detect an invocation with an empty argument list.

  • ✗

    Whether the script has any syntax errors

    Why it's wrong here

    $# holds the count of positional parameters, so the test compares that number to zero; it never parses the script's syntax. Syntax errors are reported by bash -n or at parse time, which is the check a developer would run when validating a script before execution.

  • ✗

    Whether the script is running as root

    Why it's wrong here

    Root status is exposed through $EUID or id -u, not $#, which counts positional parameters. Checking the effective user ID is the correct approach when a script must refuse to run without elevated privileges, a common guard in administrative automation.

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 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.