LPI
010-160 · Question #58
010-160 Question #58: Real Exam Question with Answer & Explanation
The correct answer is A: do. A bash for loop requires the do keyword between the in clause and the loop body commands.
Question
What keyword is missing from the following segment of the shell script? for i in *; cat $i done
Options
- Ado
- Bthen
- Cenod
- Dfi
- Erun
Explanation
A bash for loop requires the do keyword between the in clause and the loop body commands.
Common mistakes.
- B. then is used to begin the body of an if statement, not a for loop.
- C. enod is not a valid keyword in any POSIX shell or bash; it does not exist in standard shell syntax.
- D. fi closes an if-then-fi block and plays no role in for loop structure.
- E. run is not a shell control-flow keyword and is not part of any standard shell loop construct.
Concept tested. Bash for loop syntax and required keywords
Reference. https://www.gnu.org/software/bash/manual/bash.html#Looping-Constructs
Community Discussion
No community discussion yet for this question.