[QUESTION] While umatched error | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

[QUESTION] While umatched error

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-18-2012
Ryuinferno Ryuinferno is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 2 September 2013, 11:28 AM EDT
Posts: 9
Thanks: 8
Thanked 0 Times in 0 Posts
[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  
Old 11-18-2012
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 21 August 2014, 6:57 PM EDT
Location: Amsterdam
Posts: 9,310
Thanks: 268
Thanked 2,316 Times in 2,077 Posts
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  
Old 11-18-2012
Ryuinferno Ryuinferno is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 2 September 2013, 11:28 AM EDT
Posts: 9
Thanks: 8
Thanked 0 Times in 0 Posts
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  
Old 11-18-2012
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 21 August 2014, 6:57 PM EDT
Location: Amsterdam
Posts: 9,310
Thanks: 268
Thanked 2,316 Times in 2,077 Posts
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  
Old 11-18-2012
Ryuinferno Ryuinferno is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 2 September 2013, 11:28 AM EDT
Posts: 9
Thanks: 8
Thanked 0 Times in 0 Posts
*face palm* silly me...what a typo...thanks!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 11:56 PM.