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
gildan2020Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rfr1tzCommented:
test is an old bourne shell construction. Probably better is shown below. Also, I moved the read statement inside the loop.

char='x'
while [[ -n $char ]]
  do
    echo -n "character:"
    read char
    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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimbbCommented:
"test is an old bourne shell construction"

Nothing wrong with learning how to write scripts portably whenever possible.
0
rfr1tzCommented:
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.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

jimbbCommented:
Roger that, I usually use "if test -n" or "if [ -n". ;)
0
gildan2020Author Commented:
well, thanx for ur help, rfr1tz

i'll keep in mind of both ur comments :-)
0
gildan2020Author Commented:
i hav to alter the codes a bit in order for it to work with my
situation...anyway...it reli helps
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.