Beware of infinite loops.
The ability to loop is a very powerful feature of bash scripting. Loops have a variety of use cases. .
In this tutorial you will explore the three different bash loop structures. You will also learn how to use loops to traverse array elements. .
Furthermore you will learn how to use break and continue statements to control loops and finally you will learn how to create infinite loops.
For loops are one of three different types of loop structures that you can use in bash. There are two different styles for writing a for loop.
If you are familiar with a C or C like programming language then you will recognize the following for loop syntax.
Using the aforementioned C-style syntax the following for loop will print out Hello Friend ten times.
The for loop first initialized the integer variable i to zero then it tests the condition i lt10 if true then the loop executes the line echo Hello Friend and increments the variable i by 1 and then the loop runs again and again until i is no longer less than 10.