Thursday, February 8, 2007

Printing from 1-100 using BASH for loop


This sounds very easy. But for me when I tried, I was in a confusion, as for me BASH for loop is of the form

for i in 1 2 3 4 5

in that sense I had to write

for i in 1 2 3 4 5 6 7 8 . . . . 100 (from 1 to 100, which is a very poor way!!), I never knew that we can write the same this way

for ((i=1;i<101;i++))
do
echo $i
done

even in one more way

for i in `seq 100`; do echo $i; done

I found this very helpful.

No comments:

© Jadu Saikia www.UNIXCL.com