010-150 · Question #60
What keyword is missing from the following segment of the shell script? for i in *; _____ cat $i done
The correct answer is A. do. A shell for loop requires the do keyword to begin the body of the loop after the iteration expression.
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
How the community answered
(45 responses)- A80% (36)
- B4% (2)
- C11% (5)
- D2% (1)
- E2% (1)
Why each option
A shell `for` loop requires the `do` keyword to begin the body of the loop after the iteration expression.
In bash/sh shell syntax, a `for` loop follows the structure `for i in *; do ... done`. The `do` keyword is mandatory and signals the start of the loop body. Without it, the shell cannot parse the loop and will throw a syntax error.
`then` is used in `if` statements (`if condition; then`), not in `for` loops.
`enod` is not a valid shell keyword at all.
`fi` is the closing keyword for `if` blocks, not used in `for` loops.
`run` is not a valid shell keyword in this context.
Concept tested: Shell for-loop syntax and required keywords
Source: https://www.gnu.org/software/bash/manual/bash.html#Looping-Constructs
Topics
Community Discussion
No community discussion yet for this question.