Looping your way through bash

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

div#stuning-header .dfd-stuning-header-bg-container {background-image: url(https://safevoip.co.uk/wp-content/uploads/2017/04/slider.jpg);background-size: initial;background-position: top center;background-attachment: initial;background-repeat: no-repeat;}#stuning-header div.page-title-inner {min-height: 650px;}