EX200 Create simple shell scripts Practice Question
This EX200 practice question tests your understanding of create simple shell scripts. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
Refer to the exhibit.
```bash
#!/bin/bash
# Script to count lines in files
for file in *.txt; do
wc -l "$file"
done
```
Consider the script in the exhibit. The script is run in a directory containing 'a.txt' and 'b.txt' but also has a subdirectory 'backup' with .txt files. What will be the output?
Exhibit
Refer to the exhibit.
```bash
#!/bin/bash
# Script to count lines in files
for file in *.txt; do
wc -l "$file"
done
```
A
An error because the for loop cannot iterate over files with spaces
Why wrong: Incorrect. The script will not error; it will execute successfully. File names with spaces are not present in the scenario.
B
Line counts for .txt files in 'backup' only
Why wrong: Incorrect. The glob `*.txt` only matches files in the current directory, not in subdirectories like 'backup'.
C
Line counts for 'a.txt' and 'b.txt' only
Correct. The script uses `for i in *.txt`, which expands to 'a.txt' and 'b.txt' (the .txt files in the current directory). It runs `wc -l` on each, outputting their line counts.
D
Line counts for all .txt files including those in 'backup'
Why wrong: Incorrect. The glob pattern `*.txt` does not match files in subdirectories. The files in 'backup' are not processed.
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Line counts for 'a.txt' and 'b.txt' only
The script uses `for i in *.txt`, which by default only matches .txt files in the current directory, not in subdirectories. Since 'a.txt' and 'b.txt' are in the current directory, the loop iterates over them and runs `wc -l` on each, outputting their line counts. The 'backup' subdirectory is not traversed because the glob pattern does not include paths with directories.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
✗
An error because the for loop cannot iterate over files with spaces
Why it's wrong here
Incorrect. The script will not error; it will execute successfully. File names with spaces are not present in the scenario.
✗
Line counts for .txt files in 'backup' only
Why it's wrong here
Incorrect. The glob `*.txt` only matches files in the current directory, not in subdirectories like 'backup'.
✓
Line counts for 'a.txt' and 'b.txt' only
Why this is correct
Correct. The script uses `for i in *.txt`, which expands to 'a.txt' and 'b.txt' (the .txt files in the current directory). It runs `wc -l` on each, outputting their line counts.
Related concept
Read the scenario before looking for a memorised answer.
✗
Line counts for all .txt files including those in 'backup'
Why it's wrong here
Incorrect. The glob pattern `*.txt` does not match files in subdirectories. The files in 'backup' are not processed.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Red Hat often tests the candidate's understanding that shell glob patterns like `*.txt` do not recurse into subdirectories, leading many to incorrectly assume that all .txt files in the entire directory tree are processed.
Trap categories for this question
Scenario analysis trap
Incorrect. The script will not error; it will execute successfully. File names with spaces are not present in the scenario.
Detailed technical explanation
How to think about this question
The shell glob `*.txt` is expanded by the shell before the for loop runs, and it only matches filenames in the current directory. To include files in subdirectories, one would need to use `**/*.txt` with the `globstar` option enabled (shopt -s globstar) or use `find` with `-exec`. The `wc -l` command counts newline characters, so it gives the line count of each file. Without quoting `$i`, filenames with spaces would be split into multiple words, causing errors, but that is not the case here.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A practitioner preparing for the EX200 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Create simple shell scripts — This question tests Create simple shell scripts — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: Line counts for 'a.txt' and 'b.txt' only — The script uses `for i in *.txt`, which by default only matches .txt files in the current directory, not in subdirectories. Since 'a.txt' and 'b.txt' are in the current directory, the loop iterates over them and runs `wc -l` on each, outputting their line counts. The 'backup' subdirectory is not traversed because the glob pattern does not include paths with directories.
What should I do if I get this EX200 question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.