XK0-006 Automation, Orchestration, and Scripting Practice Question
A Linux administrator is writing a Bash script that must safely process a list of filenames, some of which may contain spaces or special characters. The script reads each line from a file into a variable and then iterates over the entries. Which TWO practices should the administrator follow to avoid word-splitting and globbing issues? (Choose two.)
⚠ Common exam trap
The trap here is believing that globally changing IFS or using eval will solve quoting problems, when scoped quoting and IFS= read -r are the correct targeted techniques.
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
✓
Quote the variable expansion, for example "$filename", whenever it is used in commands.
To safely handle filenames with spaces or special characters, the script should quote variable expansions so the shell treats each value as a single argument, and read lines with IFS= read -r to preserve whitespace and backslashes. These two practices together prevent word splitting and globbing from corrupting the data during iteration.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Disable globbing by running set -f at the start of the script and never re-enable it.
Why it's wrong here
While set -f disables pathname expansion, leaving it disabled for the entire script can break other parts that legitimately rely on globbing, such as patterns in case statements or file matching. It also does not address word splitting on spaces. Quoting expansions and using IFS= read -r are more targeted and correct solutions.
- ✓
Quote the variable expansion, for example "$filename", whenever it is used in commands.
Why this is correct
Quoting the variable expansion prevents the shell from performing word splitting and pathname expansion on the value. If a filename contains spaces or wildcard characters, an unquoted expansion would break it into multiple arguments or expand globs, causing the command to operate on the wrong files. Quoting preserves the value as a single argument.
- ✗
Set the IFS variable to a newline character globally at the top of the script before any commands run.
Why it's wrong here
Changing IFS globally affects all subsequent commands in the script, including those that rely on default word splitting for arguments. This can introduce subtle bugs elsewhere. The safer approach is to set IFS only for the read command, scoping the change to that single operation rather than altering global shell behavior.
- ✓
Use IFS= read -r line inside a while loop to read each line without stripping leading or trailing whitespace and without interpreting backslashes.
Why this is correct
Setting IFS= for the read command prevents leading and trailing whitespace from being trimmed, and the -r flag stops backslash interpretation. This combination ensures that each line, including those with spaces or backslashes, is captured exactly as it appears in the file, which is essential when filenames may contain such characters.
- ✗
Use the eval command to expand the variable so that spaces are handled automatically.
Why it's wrong here
eval performs a second round of shell parsing on its arguments, which actually worsens the problem by re-interpreting special characters and spaces. It can lead to command injection and unexpected globbing. eval is not a solution for word-splitting issues and should be avoided when handling untrusted or complex filenames.
Go deeper
Related to this question
Learn chapter
Basic Shell Scripting
Key term
Shell
A shell is a computer program that provides a user interface to access an operating system's services, typically by accepting text commands.
Key term
Value
Value is the perceived worth, benefit, or usefulness that a service, product, or activity delivers to stakeholders, especially customers and the business.
About these practice questions
One of 781 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 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.