Shell Scripting for loop
The for loop moves through a specified list of values until the list is exhausted.
Syntax of for loop using in and list of values is shown below. This for loop contains a number of variables in the list and will execute for each item in the list. For example, if there are 10 variables in the list, then loop will execute ten times and value will be stored in varname.
Look at the above syntax:
We have shown an example to count 2's table within for loop.
Look at the above snapshot, our varname is table, list is specified under curly braces. Within the curly braces, first two will initialize the table from 2, 20 represents maximum value of $table and last 2 shows the increment by value 2.
Look at the above snapshot, it displays the 2's table as the output.
Syntax of for like C programming language.
Look at the above snapshot, condition1 indicates initialization, cond2 indicates condition and cond3 indicates updation.
We have shown an example to count the number in reverse direction.
Look at the above snapshot, this is the loop script. $i will initialize with 10 and will go till 1, decrementing with 1 value.
Look at the above snapshot, this is the output of the script.
Next TopicWhile loop