XK0-006 Automation, Orchestration, and Scripting Practice Question
A systems administrator is writing a bash script that must accept command-line options: -f for a configuration file, -v for verbose mode, and -d for a directory. Which TWO of the following are correct ways to parse these options using getopts? (Select TWO).
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
✓
while getopts ':f:vd:' opt; do
getopts option string 'f:vd:' means -f requires an argument, -v is boolean, -d requires an argument. The colon after f and d indicates argument required.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
while getopts 'f v d' opt; do
Why it's wrong here
Spaces are not allowed; getopts expects a single string with no spaces.
- ✗
while getopts 'f:vd' opt; do
Why it's wrong here
This does not require an argument for d.
- ✓
while getopts ':f:vd:' opt; do
Why this is correct
Leading colon suppresses error messages; same effect as A for option parsing.
- ✗
while getopts 'fv:d:' opt; do
Why it's wrong here
This makes f boolean and v require argument, which is not intended.
- ✓
while getopts 'f:vd:' opt; do
Why this is correct
Correct option string with required arguments for f and d, and boolean v.
Go deeper
Related to this question
Learn chapter
File Permissions and Ownership
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.
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.
About these practice questions
This XK0-006 question is part of Courseiva's 979-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.