What keyword is used in a shell script to begin a loop?

Prepare for the LPI Linux Essentials 010-160 Test. Study with flashcards and multiple choice questions, each question offers hints and explanations. Get ready to ace your exam!

The keyword that is commonly used to begin a loop in a shell script is "while" or "for," depending on the type of loop you want to create. The "for" keyword is specifically used to start a "for loop," which iterates over a list of items or a range of values provided.

In the context of a "for loop," the syntax typically looks like this:


for variable in list

do

# commands to execute

done

Here, "for" initiates the loop, allowing you to execute a set of commands for each item in the specified list. This structure allows for flexible control over the number and nature of iterations based on elements in a list.

It's important to note that "while" is also a valid keyword to begin a loop, but it is specifically used for a different kind of loop that continues while a specified condition is true. The "do" keyword, meanwhile, is used to introduce the block of commands that will be executed within the loop, following either "for" or "while."

Thus, the identification of "for" as a keyword that begins a loop is accurate in the context of for loops specifically.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy