Link to home
Start Free TrialLog in
Avatar of gildan2020
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
ASKER CERTIFIED SOLUTION
Avatar of rfr1tz
rfr1tz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jimbb
jimbb

"test is an old bourne shell construction"

Nothing wrong with learning how to write scripts portably whenever possible.
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.
Roger that, I usually use "if test -n" or "if [ -n". ;)
Avatar of gildan2020

ASKER

well, thanx for ur help, rfr1tz

i'll keep in mind of both ur comments :-)
i hav to alter the codes a bit in order for it to work with my
situation...anyway...it reli helps