Wednesday, October 30, 2019

Looping your way through bash

There are a lot of options for looping in bash whether on the command line or in a script. The choice depends on what you're trying to do.

You may want to loop indefinitely or quickly run through the days of the week. You might want to loop once for every file in a directory or for every account on a server. You might want to loop through every line in a file or have the number of loops be a choice when the script is run. Let's check out some of the options.

Simple loops

Probably the simplest loop is a for loop like the one below. It loops as many times as there are pieces of text on the line. We could as easily loop through the words cats are smart as the numbers 1, 2, 3 and 4.

To read this article in full, please click here


Thanks to Sandra Henry-Stocker (see source)

No comments:

Post a Comment