nerdexam
LPI

010-160 · Question #58

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 bash for loop requires the do keyword between the in clause and the loop body commands.

The Power of the Command Line

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

(35 responses)
  • A
    94% (33)
  • B
    3% (1)
  • E
    3% (1)

Why each option

A bash for loop requires the do keyword between the in clause and the loop body commands.

AdoCorrect

The correct POSIX/bash for loop syntax is: for i in *; do <commands>; done. The do keyword is mandatory and marks the beginning of the loop body; its absence causes an immediate syntax error from the shell.

Bthen

then is used to begin the body of an if statement, not a for loop.

Cenod

enod is not a valid keyword in any POSIX shell or bash; it does not exist in standard shell syntax.

Dfi

fi closes an if-then-fi block and plays no role in for loop structure.

Erun

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

Source: https://www.gnu.org/software/bash/manual/bash.html#Looping-Constructs

Topics

#shell scripting#for loop#do keyword#bash syntax

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice