The C-Style for Command
If you've done any programming using the C programming language, you're probably surprised by the way the bash shell uses the for
command. In the C language, a for
loop normally defines a variable, which it then alters automatically during each iteration. Typically, programmers use this variable as a counter and either increment or decrement the counter by one in each iteration. The bash for
command can also provide this functionality. This section shows you how to use a C-style for
command in a bash shell script.
The C language for command
The C language for
command has a specific method for specifying a variable, a condition that must remain true for the iterations to continue, and a method for altering the variable for each iteration. When the specified condition becomes false, the for
loop stops. The condition equation is defined using standard mathematical symbols. For example, consider the following C language code:
for (i = 0; i < 10; i++...