EX200 Create simple shell scripts Practice Question
Exhibit
Refer to the exhibit. ```bash #!/bin/bash for file in $(ls /etc/*.conf); do echo "Processing: $file" done ```
A system administrator writes the script shown. The /etc directory contains .conf files with spaces in their names (e.g., "my config.conf"). What is the most accurate description of the script's behavior?
⚠ Common exam trap
Red Hat often tests the misconception that globbing automatically handles spaces, when in fact unquoted expansions cause word splitting that breaks filenames with spaces.
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
✓
The script will split filenames with spaces into multiple words, causing errors.
The script uses a for loop with `for file in /etc/*.conf`, which relies on shell globbing. When the glob expands, filenames with spaces (e.g., "my config.conf") are treated as separate words due to word splitting, causing the loop to iterate over each word rather than each file. This results in errors when commands like `echo` or `cp` receive broken paths.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The script will correctly process all .conf files, including those with spaces.
Why it's wrong here
This is incorrect. The for-loop uses unquoted `$(ls /etc/*.conf)`, and the shell performs word splitting on the command substitution's output. Any filename containing spaces is broken into separate words, so the loop iterates over partial names such as "my" and "config.conf" instead of the single file "my config.conf". The script will therefore try to access files that do not exist and will not process all .conf files correctly.
- ✗
The script will only process the first .conf file and then exit.
Why it's wrong here
This is incorrect. A standard `for file in ...` loop iterates over every item in the generated word list; it does not exit or break after the first iteration unless the loop body contains an explicit `break` or `exit`, which is not present. The `ls` command inside the command substitution produces all matching filenames, and the shell converts them into a list of words. Consequently, the loop will continue through all of those words, not just the first.
- ✗
The script will not execute because of a syntax error.
Why it's wrong here
This is incorrect. The construct `for file in $(ls /etc/*.conf); do ...; done` is syntactically valid Bash; command substitution and a `for` loop form a valid list. The problem is not a syntax error but a logic error: the unquoted substitution causes word splitting and potential pathname expansion. The script will run, but it will misbehave when filenames contain spaces, so the failure is in runtime semantics, not parsing.
- ✓
The script will split filenames with spaces into multiple words, causing errors.
Why this is correct
This is the correct behavior. When the command substitution `$(ls /etc/*.conf)` is left unquoted, the shell splits the result using the characters in `IFS` (space, tab, and newline by default). A file named, for example, `app config.conf` becomes two loop tokens, `app` and `config.conf`, causing the loop body to run extra times with incorrect arguments. These partial names are unlikely to exist, so the script produces errors and fails to handle the actual .conf files that have spaces.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX200 question from scratch — 427 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 →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This EX200 practice question is part of Courseiva's free Red Hat 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 EX200 exam.