33FLOW CONTROL: LOOPING WITH FOR

image

In this final chapter on flow control, we will look at another of the shell’s looping constructs. The for loop differs from the while and until loops in that it provides a means of processing sequences during a loop. This turns out to be very useful when programming. Accordingly, the for loop is a popular construct in bash scripting.

A for loop is implemented, naturally enough, with the for compound command. In bash, for is available in two forms.

for: Traditional Shell Form

The original for command’s syntax is as follows:

for variable [in words]; do      commandsdone

where variable is the name of a variable that ...

Get The Linux Command Line, 2nd 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.