Let's explore two more options for assisting with iteration. The while construct allows for the repetitive execution of a list or set of commands as long as the command that controls the while loop exits successfully. Let's see an example:
Let's say I wanted to print the "hello!" string four times in a script—no more and no less. We can do so with the following:
Let's save and run this script to see what happens.
Don't forget to chmod -x these scripts to make them executable.
Executing the script produces the following:
Notice that, in the script, we created a variable called i="0". This sets the i variable to zero. Do you see the while [ $i -lt 4 ] block? This allows us to run the loop as the i variable is less than the 4 integer. Go ahead and play around with this...