for loop in the shell a tutorial

There are two syntaxes that can be used for a for loop in a linux shell , the first one is more sparse , as in :

for var in words
do
# The program
done

The second one is more terse as in :

for var in words ; do Program ; done ;

Here are some examples to illustrate the two syntaxes :

As with every other program which is run in the shell , the output of the for loop can be redirected to a file , or piped to another program . And the for loop can be run as a background job .

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store