O'Reilly logo

The Linux Command Line by William E. Shotts Jr.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

for: C Language Form

Recent versions of bash have added a second form of for-command syntax, one that resembles the form found in the C programming language. Many other languages support this form, as well.

for (( expression1; expression2; expression3 )); do
        commands
done

where expression1, expression2, and expression3 are arithmetic expressions and commands are the commands to be performed during each iteration of the loop.

In terms of behavior, this form is equivalent to the following construct:

(( expression1 ))
while (( expression2 )); do
        commands
        (( expression3 ))
done

expression1 is used to initialize conditions for the loop, expression2 is used to determine when the loop is finished, and expression3 is carried out at the end of each iteration ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required