easyMultiple ChoiceObjective-mapped
XK0-006 Practice Question: A DevOps engineer is writing a Bash script to…
A DevOps engineer is writing a Bash script to check if the configuration file /etc/myapp.conf exists and is readable. The script must exit with code 0 if the file is readable, and exit with code 1 otherwise. The script will be used on systems with Bash as the default shell. Which code snippet correctly implements this logic using the most efficient syntax available in Bash?
⚠ Common exam trap
The CompTIA Linux+ exam often tests the distinction between POSIX test constructs and Bash-specific enhancements, trapping candidates who assume single-bracket or test syntax is equally efficient or correct for Bash-only environments.
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
✓
`if [[ -r /etc/myapp.conf ]]; then exit 0; else exit 1; fi`
The double-bracket [[ ... ]] construct is a Bash keyword that provides enhanced test functionality, including pattern matching and more efficient parsing without word splitting or pathname expansion. It directly supports the -r operator to check if a file is readable, and the script exits 0 if true, 1 otherwise, using the most efficient syntax available in Bash.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
`if [ -r /etc/myapp.conf ]; then exit 0; else exit 1; fi`
Why it's wrong here
This is POSIX-compliant but not the most efficient in Bash.
- ✗
`if test -r /etc/myapp.conf; then exit 0; else exit 1; fi`
Why it's wrong here
This is another POSIX-compliant way, less efficient in Bash.
- ✗
`if ( -r /etc/myapp.conf ) then exit 0; else exit 1; fi`
Why it's wrong here
Invalid syntax; parentheses are not used for test commands.
- ✓
`if [[ -r /etc/myapp.conf ]]; then exit 0; else exit 1; fi`
Why this is correct
[[ ]] is Bash-specific, more efficient for file tests.
Visual reference
Go deeper
Related to this question
Learn chapter
File Permissions and Ownership
Key term
Bash
Bash is a command-line interpreter that lets users interact with an operating system by typing text commands instead of clicking icons.
Key term
Bash script
A Bash script is a text file containing a sequence of commands for the Unix shell Bash, allowing users to automate repetitive tasks and streamline system administration on Linux and macOS.
About these practice questions
One of 979 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 →
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.