for_loop


for_loop, BASH codes which illustrate the use of the FOR loop.

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Source Code:

for_loop_alphabet shows how a FOR loop can be used to a range of alphabetic characters, such as A to Z.

for_loop_numeric shows how a FOR loop can be used to repeat a set of commands with a variable set to each numeric value in a list.

for_loop_range shows how a FOR loop can be used to repeat a set of commands with a variable set to each numeric value in a range.

for_loop_skip shows how a FOR loop can be used to repeat a set of commands with a variable set to each numeric value in a range, with a skip between successive values.

for_loop_string shows how a FOR loop can be used to process a list of string items. In this case, we simply want to say happy birthday to John and Bob and Mary, but in a real application, we might want to carry out a sequence of operations to /usr/work/$USER and to /usr/home/$USER and to /usr/temp/$USER.

for_loop_stdout shows how a FOR loop can be used to process the items returned as the standard output of a command such as "ls".


Last revised on 16 December 2020.