Iteration Statements

Iteration statements are used to repeat a series of commands contained within the iteration statement.

The for Statement

The for statement has a number of formats. The first format is as follows:

for curvar in list
do
    statements
done

This form should be used if you want to execute statements once for each value in list. For each iteration, the current value of the list is assigned to vcurvar. list can be a variable containing a number of items or a list of values separated by spaces. This format of the for statement is used by pdksh and bash.

The second format is as follows:

for curvar
do
    statements
done

In this form, the statements are executed once for each of the positional parameters passed to the shell program. ...

Get Red Hat® Linux® 7 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.