Linux Essentials (010-160) — Question 31
Which of the following examples shows the general structure of a for loop in a shell script?
Answer options
- A. for *.txt as file => echo $file
- B. for *.txt ( echo $i )
- C. for file in *.txt do echo $i done
- D. for ls *.txt exec {} \;
- E. foreach @{file} { echo $i }
Correct answer: C
Explanation
Option C is correct because it accurately represents the syntax of a for loop in a shell script, using 'for file in *.txt' followed by the commands to execute. The other options either use incorrect syntax or are not valid constructs in a shell script context.