nerdexam
LPI

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.

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

(45 responses)
  • A
    80% (36)
  • B
    4% (2)
  • C
    11% (5)
  • D
    2% (1)
  • E
    2% (1)

Why each option

A shell `for` loop requires the `do` keyword to begin the body of the loop after the iteration expression.

AdoCorrect

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.

Bthen

`then` is used in `if` statements (`if condition; then`), not in `for` loops.

Cenod

`enod` is not a valid shell keyword at all.

Dfi

`fi` is the closing keyword for `if` blocks, not used in `for` loops.

Erun

`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

#shell scripting#for loop#bash syntax#control structures

Community Discussion

No community discussion yet for this question.

Full 010-150 Practice