![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| while loop inside while loop | panknil | Shell Programming and Scripting | 0 | 01-07-2008 12:49 PM |
| For loop | xramm | HP-UX | 3 | 10-10-2007 02:20 PM |
| For Loop help | princssashes | UNIX for Dummies Questions & Answers | 2 | 11-09-2006 05:37 AM |
| for loop | munnabhai1 | Shell Programming and Scripting | 3 | 04-06-2006 02:30 PM |
| how to get the similar function in while loop or for loop | trynew | Shell Programming and Scripting | 3 | 06-17-2002 11:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hello,
I have HP-UX 11 at work. Below is a part of the script I'm writing. User gets prompted to enter environment type. The While loop checks if the entered value is either P or D. If neither of two is entered, then the scripts prompts to enter the value again. - If correct environment type is passed, it still enters the infinite loop - If incorrect environment type is passed, I get prompted to re-enter. Upon entering the correct value, I'm still in the infinite loop. Please help. Thank you. 1 #!/bin/ksh 2 3 echo "Please enter environment type:" 4 read environment 5 6 while [ $environment != "P" ] || [ $environment != "D" ] 7 do 8 echo "Invalid environment entered. Please enter environment type again:" 9 read environment 10 done 11 echo $environment |
|
||||
|
Try using && instead of ||. With ||, it will keep looping if either of those statements is false, and since they can never both be true at the same time, this causes an infinite loop. && only keeps the loop going when they are BOTH false, if one is true then the loop will break.
|
|
||||
|
Thank you.
That worked. I was under impression to have OR and not AND. But, now I understand that the AND here does not mean they both have to be true, but And means that we need to test more than one variable (in this case same variable being tested twice). Thanks again ![]() |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|