Question 340
Original unofficial RHEL 10 RHCSA skill-check scenario: A shell loop intended to count processed files prints the same counter because it is updated in a pipeline subshell. Which ongoing practice best prevents a recurrence?
Explanation
Correct Answer
In this RHEL 10 system administration case: A shell loop intended to count processed files prints the same counter because it is updated in a pipeline subshell. Underlying reason: A piped loop can run in a separate shell environment. The most direct, approved resolution is: Use a loop input pattern that preserves the intended shell scope or count outside the subshell. Confirm it by checking: The reported count equals the number of processed records. Sustain the fix by: Test stateful loop counters with multiple records. This is the INTENDED response for the best ongoing operational safeguard. It is a knowledge-check explanation, not a verified hands-on Red Hat exam answer;
Incorrect Answers
Apply allowlisted paths for destructive loops. That is not sufficient for the reported RHEL task, because a piped loop can run in a separate shell environment.
Include paths with spaces in argument validation tests. That is not sufficient for the reported RHEL task, because a piped loop can run in a separate shell environment.
Use shellcheck or shell syntax checks on new scripts. That is not sufficient for the reported RHEL task, because a piped loop can run in a separate shell environment.