LFCS · Question #534
What keyword is missing from this code sample of a shell script? ____ i in *.txt; do echo $i done
The correct answer is A. for. The missing keyword in the shell script code sample for iterating over files is for, used to construct a for loop.
Question
Options
- Afor
- Bloop
- Cuntil
- Dwhile
How the community answered
(35 responses)- A91% (32)
- B3% (1)
- C6% (2)
Why each option
The missing keyword in the shell script code sample for iterating over files is `for`, used to construct a `for` loop.
In shell scripting, `for i in *.txt; do echo $i; done` is the standard syntax for a `for` loop that iterates through all files matching the pattern `*.txt`, assigning each filename to the variable `i` for processing within the loop's `do...done` block. The `for` keyword introduces this iterative control structure.
`loop` is not a standard keyword for creating iterative loops in bash scripting; it is often part of a loop's description, not its syntax.
`until` is a keyword used for a loop that continues until a condition becomes true, with a different syntax (`until condition; do commands; done`).
`while` is a keyword used for a loop that continues as long as a condition is true, also with a different syntax (`while condition; do commands; done`).
Concept tested: Bash `for` loop syntax
Source: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Looping-Constructs
Topics
Community Discussion
No community discussion yet for this question.