Question 80
The engineer proposes this implementation: Use a Bash arithmetic loop or for n in 1 2 3 4 5; do ...; done. The requirement is: A script must handle each integer from 1 to 5 without a nonportable external loop program. Which technical explanation best supports the proposed action?
Explanation
Correct Answer
A for loop iterates over a finite list; the iteration count is bounded and explicit. It specifically supports the proposed action of Use a Bash arithmetic loop or for n in 1 2 3 4 5; do ...; done. for the requirement described.
Incorrect Answers
This explains another Linux operation, namely Use primary-command || fallback-command with defined exit statuses., where The || operator evaluates its right-hand command only after a nonzero status on the left. It does not explain why Use a Bash arithmetic loop or for n in 1 2 3 4 5; do ...; done. satisfies the stated condition.
This explains another Linux operation, namely Use a conditional test such as if [ -z "$input" ]; then ...; fi., where The -z string test returns success when its argument has zero length, including an unset variable expanded as empty. It does not explain why Use a Bash arithmetic loop or for n in 1 2 3 4 5; do ...; done. satisfies the stated condition.
This explains another Linux operation, namely Run exec /path/to/program in the script at the handoff point., where The exec builtin replaces the shell process rather than spawning a shell child that later waits. It does not explain why Use a Bash arithmetic loop or for n in 1 2 3 4 5; do ...; done. satisfies the stated condition.






LPI Level 1 (102-500) Practice Tests