Courseiva
easyMultiple Choice

XK0-006 Practice Question: A systems administrator writes a Bash script…

A systems administrator writes a Bash script named 'backup.sh' and wants it to run with the Bash shell. Which line should appear first in the script?

⚠ Common exam trap

CompTIA often tests the distinction between a shebang (`#!`) and a comment (`#`), and the trap here is that candidates may confuse `#!/bin/sh` as equivalent to `#!/bin/bash` or forget the exclamation mark entirely, leading them to choose option C or D.

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

✓

#!/bin/bash

The shebang line `#!/bin/bash` is required as the first line to instruct the operating system to execute the script using the Bash shell interpreter located at `/bin/bash`. Without this line, the script may be run by a different shell (e.g., `/bin/sh`), leading to syntax or behavior differences. The shebang must start with `#!` followed by the absolute path to the interpreter.

Answer analysis

Option-by-option breakdown

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

  • ✗

    # This is a bash script

    Why it's wrong here

    A comment line is ignored by the shell, so it cannot declare an interpreter; the kernel needs a shebang such as #!/bin/bash on line one to invoke Bash. Comments document scripts and are valid anywhere, which makes this tempting, but they never control execution.

  • ✓

    #!/bin/bash

    Why this is correct

    The shebang line `#!/bin/bash` must be the first line, as it tells the kernel to invoke `/bin/bash` as the interpreter for the script. This satisfies the stem's requirement that the script run specifically with the Bash shell, rather than the default shell or another interpreter.

  • ✗

    #/bin/bash

    Why it's wrong here

    A shebang requires the two characters '#!' followed by the interpreter path; '#/bin/bash' has no exclamation mark, so the kernel treats the line as an ordinary comment and runs the script under the invoking shell. It is tempting because the path and hash are present, but only '#!/bin/bash' selects Bash.

  • ✗

    #!/bin/sh

    Why it's wrong here

    '#!/bin/sh' invokes the POSIX shell, which on many distributions is dash, so Bash-specific syntax such as arrays or '[[ ]]' fails. It is tempting because sh is portable and adequate for simple scripts, but the requirement here is explicitly to run under Bash.

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.