?
Solved

while loop + case= infinity??

Posted on 2003-03-03
6
Medium Priority
?
181 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:gildan2020
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
rfr1tz earned 150 total points
ID: 8057110
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
 
LVL 2

Expert Comment

by:jimbb
ID: 8059262
"test is an old bourne shell construction"

Nothing wrong with learning how to write scripts portably whenever possible.
0
 
LVL 3

Expert Comment

by:rfr1tz
ID: 8059335
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:jimbb
ID: 8059379
Roger that, I usually use "if test -n" or "if [ -n". ;)
0
 

Author Comment

by:gildan2020
ID: 8062841
well, thanx for ur help, rfr1tz

i'll keep in mind of both ur comments :-)
0
 

Author Comment

by:gildan2020
ID: 8062842
i hav to alter the codes a bit in order for it to work with my
situation...anyway...it reli helps
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question