102-500 practice question 10 of 30
What keyword is missing from this code sample of a shell script? ____ i in *.txt; do echo $i done
Full set: 233 questionsThe code sample shows the syntax for a for loop in a shell script. The for loop is used to iterate over a list of items and perform a set of commands for each item. The general syntax is for name [in words ...]; do commands; done. In the provided example, i is the variable, and .txt is a glob pattern that expands to a list of all files in the current directory ending with .txt. The for keyword is required to initiate this type of loop structure.
B. loop is not a standard keyword for creating loops in bash or other POSIX-compliant shells.
C. The until loop executes commands as long as its test condition is false and uses the syntax until [condition]; do ...; done.
D. The while loop executes commands as long as its test condition is true and uses the syntax while [condition]; do ...; done.
1. GNU Bash Reference Manual, Version 5.2, "3.2.4.1 The for Loop". The manual provides the syntax: for name [ [in [word ...] ] ; ] do commands; done. The example for i in .txt directly matches this pattern.
2. The Open Group Base Specifications Issue 7, 2018 edition, IEEE Std 1003.1-2017, "Shell & Utilities", Chapter 2, "Shell Command Language", Section 2.9.4 "For Loop". This standard defines the for loop with the exact syntax shown in the question.
3. Stanford University, CS107: Computer Organization & Systems, "Unix and C", Lecture 02, "Shell". Course materials cover fundamental shell scripting constructs, including the syntax and usage of the for loop for iterating over file lists.
Keep practicing
Take the free 102-500 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 102-500 practice questions
- Question 1What output is produced by the following command sequence? echo ‘1 2 3 4 5 6’ | while rea…
- Question 2Which command will set the local machine's timezone to UTC?
- Question 3Which of the following SQL statements will select the fields name and address from the co…
- Question 4Which of the following commands can remove a user from a group?
- Question 5Where are user specific crontabs stored?
- Question 6Which of the following crontab entries will execute myscript at 30 minutes past every hou…
