The for Statement
You use the for
statement to execute a set of commands once each time a specified condition is true. The for
statement has a number of formats. The first format used by pdksh
and bash
is as follows:
for curvar in listdo statementsdone
You should use this form 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. The second format is as follows:
for curvardo statementsdone
In this form, the statements
are executed once for each of the positional parameters passed to the shell program. For each iteration, the current value of the positional parameter ...
Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition 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.