gildan2020
asked on
while loop + case= infinity??
hello every1...i hope u all can help me with this code:
-------------------------- ---------- ---------- ---------
echo -n "character:"
read char
while test -n $char
do
case $char in
a)echo "you typed a";;
b)echo "you typed b";;
c)echo "you typed c";;
*)echo "you typed something else";;
esac
done
-------------------------- ---------- ---------- ---------
da prob is...da result will keep looping non-stop
how do i prevent dis infinite loop or is there another better method?
i'm using bash shell in mandrake linux 9.0 to generate da codes.
gildan2020
--------------------------
echo -n "character:"
read char
while test -n $char
do
case $char in
a)echo "you typed a";;
b)echo "you typed b";;
c)echo "you typed c";;
*)echo "you typed something else";;
esac
done
--------------------------
da prob is...da result will keep looping non-stop
how do i prevent dis infinite loop or is there another better method?
i'm using bash shell in mandrake linux 9.0 to generate da codes.
gildan2020
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's up to you. I have never used "test" that I can remember. In additon, I would not have used [[ -n ... either
I would have used an if statement instead because it is more readable.
I would have used an if statement instead because it is more readable.
Roger that, I usually use "if test -n" or "if [ -n". ;)
ASKER
well, thanx for ur help, rfr1tz
i'll keep in mind of both ur comments :-)
i'll keep in mind of both ur comments :-)
ASKER
i hav to alter the codes a bit in order for it to work with my
situation...anyway...it reli helps
situation...anyway...it reli helps
Nothing wrong with learning how to write scripts portably whenever possible.