Hi people,
I have a small bash script in which i use "while" or "for" loop and none of them are working.
This below is the part that's giving me head aches:
Code:
if [ "$1" == "z" ] && [ ! -z "$2" ] ; then
no=1; end=100
while [ $no -lt $end ] ; do
if [ ! -f "file.$no" ] ; then
break
fi
done
echo "$no"
fi
so this above sais that if argument 1 is "z" and argument 2 exists, loop until find file named file.$no
and break and of course remember the last $no.
when searching for file.$no it loops from 1 to 100 and the first file it finds is file.8 so it should return no=8
why is it returning no=1 ??
i tried for loop like this:
Code:
if [ "$1" == "z" ] && [ ! -z "$2" ] ; then
no=1; end=100
for (( $no; $no<$end; $no++ )) ; do
if [ ! -f "file.$no" ] ; then
break
fi
done
echo "$no"
fi
and same result ... no=1
Can someone please help me with this?