|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[SOLVED] While umatched error
Hi guys...was trying to use while loop and a sentry to prompt user input again if an invalid option was entered...but somehow I got a "while" unmatched error...The code is as below: Code:
#!/system/bin/sh finsh=0 while [ $finish -ne 0 ] do echo "Please select an option: " echo "1. One" echo "2. Two" echo "3. Three" echo "4. Exit" echo -n "Enter your selection: "; read opt if [ $opt -eq 1 ]; then echo "Please enter your next selection: " echo "1. ABC" echo "2. DEF" echo "3. Main Menu" subopt=0 while [ $subopt -lt 1 ] || [ $subopt -gt 3 ] do echo -n "Enter your selection: "; read subopt if [ $subopt -eq 1 ]; then echo "ABC" echo "Hit enter to continue..." read enterKey elif [ $subopt -eq 2 ]; then echo "EFG" echo "Hit enter to continue..." read enterKey elif [ $subopt -eq 3 ]; then echo "Returning to main menu" echo "Hit enter to continue..." read enterKey else echo "Invalid option, please try again..." fi done elif [ $opt -eq 2 ]; then echo "Two" echo "Press enter to continue..." read enterKey elif [ $opt -eq 3 ]; then echo "Three" echo "Press enter to continue..." read enterKey elif [ $opt -eq 4 ]; then echo "Bye!" finish=1 else echo "Invalid option, please try again" fi done exit Thanks in advance...
Last edited by Ryuinferno; 11-18-2012 at 10:54 PM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Hi,
$finish does not get initialized prior to the while loop. One the line above that there is probably a typo, but even if it were set to zero, the while loop would not be entered..
|
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
Ryuinferno (11-18-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Ok...but even though I set the condition for the while loop as [ $finish -ne 1 ], I still get the same error...what should I do to make a correct initialisation?
|
|
#4
|
||||
|
||||
|
You need to initialize the variable prior to the while loop test. The line above contains "finsh" instead of "finish"
|
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
Ryuinferno (11-18-2012) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
*face palm* silly me...what a typo...thanks!
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error redirection question | calredd | Shell Programming and Scripting | 3 | 09-15-2011 04:39 PM |
| Newbie Question.. -> error: syntax error before ';' token | reelflytime | Programming | 3 | 07-29-2009 12:54 PM |
| C Question compilation error | jaganreddy | Programming | 1 | 05-12-2008 10:05 AM |
| Question about error | Howeird | UNIX for Advanced & Expert Users | 3 | 04-26-2002 07:59 AM |
| Error Question | djatwork | UNIX for Dummies Questions & Answers | 4 | 10-04-2001 05:47 PM |
|
|