Question 60
A Linux administrator faces this requirement: A cleanup script must process each pathname found in a controlled array one at a time without splitting spaces. Which specific action is the best direct solution?
Explanation
Correct Answer
Iterate using for path in "${files[@]}"; do ...; done. The mechanism is: Quoted array expansion preserves element boundaries; unquoted word splitting can break file names containing spaces.
Incorrect Answers
Use IFS= read -r answer for a whole response line. That operation is designed for the different case: A scripted review should ask an operator for an explicit response and store it safely in a variable. It does not perform the specific action required here: Iterate using for path in "${files[@]}"; do ...; done.
Use primary-command || fallback-command with defined exit statuses. That operation is designed for the different case: An emergency recovery script must invoke a fallback command only when its primary probe fails. It does not perform the specific action required here: Iterate using for path in "${files[@]}"; do ...; done.
Use a Bash arithmetic loop or for n in 1 2 3 4 5; do ...; done. That operation is designed for the different case: A script must handle each integer from 1 to 5 without a nonportable external loop program. It does not perform the specific action required here: Iterate using for path in "${files[@]}"; do ...; done.






LPI Level 1 (102-500) Practice Tests