The ability to loop is a very powerful feature of bash scripting. For example, let's say you want to print out the line "Hello world" 20 times on your terminal; a naive approach would be to create a script that has 20 echo statements. Luckily, looping offers a smarter solution.
Using the for loop
The for loop has a few different syntaxes. If you are familiar with C++ or C programming, then you will recognize the following for loop syntax:
for ((initialize ; condition ; increment)); do
// do something
done
Using the aforementioned C-style syntax; the following for loop will print out "Hello World" twenty times:
for ((i = 0 ; i < 20 ; i++)); do
echo "Hello World"
done
The loop initializes the integer variable i to 0, then it tests the condition (i < 20); if true, it then executes the line echo "Hello World" and increments the variable i by one, and then the loop runs again and again until i is no longer less than...