If you are stubborn C programmer and wish to get your way when using BASH you will be happy to know that BASH offers C style syntax for writing for loops. Below you can find two examples of C style bash for loop:

Simple c-style bash for look with three iterations:
for ((i=1; i <= MAX ; i++)) ; do
	echo "$i"

c-style for loop used to print all array elements:

ARRAY=( 'Debian Linux' 'Redhat Linux' 'Ubuntu Linux' )

for (( i=0;i<$ELEMENTS;i++)); do
    echo ${ARRAY[${i}]}

Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Go to top