C-style for loops

If you have a C language background, you will be happy to know that you can write your for loops in C-style. This feature was taken from KornShell. The shell for loop can be written like this:

for (v= 0; v < 5; v++) 
{ 
 printf(Value is %d\n", v); 
} 

It is easy for C developers to use this syntax in for loops.

Check out this example:

#!/bin/bash 
for (( v=1; v <= 10; v++ )) 
do 
   echo "value is $v" 
done 

The choice is yours; you have a lot of syntax styles for the for loop.

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.