Friday, 27 September 2013

Defining ranges in bash for loops didn't work

Defining ranges in bash for loops didn't work

I have the following for loop in bash that creates loop devices in a
chrooted directory.
for var in 0 1 2 3 .. 7
do
MAKEDEV -d ${CHROOT}/dev -x loop$var
done
This didn't work for me as after it creates loop3 it takes .. literally
and tries to create loop.. and fails. However according to this tutorial
it should have worked. I got it to work by doing the following:
for (( var=0; var<=7; var++ ))
do
MAKEDEV -d ${CHROOT}/dev -x loop$var
done
I still want to know why the for loop I tried first didn't work. Please help.

No comments:

Post a Comment