• Home
  • Reviews
  • Articles
  • News
  • Tools
  • GamingHeaven
  • Forums
  • Network
 

Go Back   DriverHeaven.net > Forums > Software / Tools > Linux Operating Systems

Notices

Reply
 
LinkBack Thread Tools
Old Sep 21, 2004, 03:03 PM   #1
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

Problem: Ending multiple case statements

Okay i want a case statement within my case statement.

I will show you guys my code if you can help me figure out how to get this to work. thanks!

Kornshell shell script

What i think is happening is i am closing the first CASE out with esac in the 5) choice asi was trying to make another case statement to exit my menu. Or do i need to change my loop or start a new loop im all confused! My errors start on line 104 or whatever right after i use my esac in 5)

EDIT: Took out that esac... now i get unexpected done on line 110 and there are only 109 lines in this thing now what do i do lol?

thanks for your help

#!/usr/bin/ksh
#
###########################
#
#Author: GS
#
###########################
#
#Date Edited: 9-16-04:
#
###########################
#
#Date Edited: 9-16-04
#
###########################
#
#Whom:
#
###########################
#
#Why: To create a working script
#
###########################
#
#Variables: CHOICE
#
###########################
#
#
#
#
while true
do
clear
echo "____________________________________"
echo "| |"
echo "| Main |"
echo "| |"
echo "|----------------------------------|"
echo "| |"
echo "| 1) Show Directory |"
echo "| 2) Insert Option |"
echo "| 3) Inster Option |"
echo "| 4) Insert Option |"
echo "| 5) Exit |"
echo "| |"
echo "|__________________________________|"
echo " "
echo "Please make a choice from the given options"
read CHOICE
#
#
case $CHOICE in
1) clear
ls -al
echo "Please press any key"
read
;;
#
#
2) clear
echo "This option is currently under construction"
echo "Please press any key"
read
;;
#
#
3) clear
echo "This option is currently under construction"
echo "Please press any key"
read
;;
#
#
4) clear
echo "This option is currently under construction"
echo "Please press any key"
read
;;
#
#
#
5) clear
echo "Would you like to exit the system? y/n"
read ANS
case $ANS in
y) clear
echo "Thank You"
echo "Please press any key to exit"
read
exit
;;
n) clear
;;
*) clear
echo "Invalid response please use y or n"
echo "Press any key to return to the menu"
read
;;
esac
#
*) clear
echo "Invalid response, Please use a given choice (1,2,3,4,5)"
echo "Please press any key to continue"
read
;;
esac
done

Last edited by GutterPunk; Sep 21, 2004 at 03:10 PM.
GutterPunk is offline   Reply With Quote


Old Sep 21, 2004, 09:15 PM   #2
BSD SMASH!
 
Malus's Avatar
 
Join Date: May 2002
Location: A rabbit hole. . .
Posts: 1,170
Rep Power: 0
Malus is on a distinguished road

Quote:
Originally Posted by GutterPunk
EDIT: Took out that esac... now i get unexpected done on line 110 and there are only 109 lines in this thing now what do i do lol?
That means that your script wasn't done before it reached the end of the file. Having never written a ksh script, I can't say what exactly you did wrong. I've only written sh/csh scripts, and the syntax seems a bit too different.
Malus is offline   Reply With Quote
Old Sep 21, 2004, 09:45 PM   #3
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

Okay i am past that... I will update my problem when i get home. Does anybody know how to close an embedded case statement so the main case is used in the loop. I can make it but everything past option 3 will not work (option 3 has my embedded case).
GutterPunk is offline   Reply With Quote
Old Sep 22, 2004, 04:44 AM   #4
A Legend in Underwear
 
UberLord's Avatar
 
Join Date: May 2002
Location: Unknown
Posts: 5,256
Rep Power: 0
UberLord is on a distinguished road

Code:
Please use code tags as it makes things so much easier to read
UberLord is offline   Reply With Quote
Old Sep 22, 2004, 10:42 AM   #5
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

what do you mean code tags? lol
GutterPunk is offline   Reply With Quote
Old Sep 22, 2004, 10:47 AM   #6
A Legend in Underwear
 
UberLord's Avatar
 
Join Date: May 2002
Location: Unknown
Posts: 5,256
Rep Power: 0
UberLord is on a distinguished road

Code:
this is in code tags, so it's easier to read code
this is in bold tags to get your attention
this is in italics for no apparent reason

Tags Explained

(And that was in a URL tag)
UberLord is offline   Reply With Quote
Old Sep 22, 2004, 11:01 AM   #7
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

doh i got ya! ill post my new problem in a second, if you are willing to stand by your help is most appreciated
GutterPunk is offline   Reply With Quote
Old Sep 22, 2004, 11:07 AM   #8
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

Okay, when i enter into the menu, options 1, 2, 3 are available, and 4 and 5 are not. When i comment option 3 out 4 and 5 become available once again. I am not sure on how to close my embedded case statement. I think that is where my problem is.

Code:
 
#!/usr/bin/ksh
#
###########################
#
#Author: GS
#
########################### 
#
#Date Edited: 9-16-04: 
#
###########################
#
#Date Edited: 9-16-04
#
###########################
#
#Whom: 
#
###########################
#
#Why: To create a working script
#
###########################
#
#Variables: CHOICE
#
###########################
#
#
#
#
while true
do
clear
	 echo "____________________________________"
	 echo "|								 |" 
	 echo "|			 Main			 |"
	 echo "|								 |"
	 echo "|----------------------------------|"
	 echo "|								 |"
	 echo "|	 1) Show Directory		 |"
	 echo "|	 2) Insert Option		 |"
	 echo "|	 3) Creat and move a file |"
	 echo "|	 4) Insert Option		 |"
	 echo "|	 5) Exit										 |"
	 echo "|														 |"
	 echo "|__________________________________|"
	 echo "									" 
	 echo "Please make a choice from the given options"
	 read CHOICE
#
#
	 case $CHOICE in
 
1) clear
	 ls -al
	 echo "Please press any key"
	 read
	 ;;
#
#
		2) clear
	echo "This option is currently under construction"
	echo "Please press any key"
	read
	;;
#
#
3) clear
	touch move
	mkdir door
	mv move door
	ls -al door
	echo "Please confirm the file was moved, press y for yes" 
	echo "it did move, and n for no it was unsuccessful"
		 read ANS 
	case $ANS in
			 y) clear
	rm door/move
	rmdir door
	ls -al
				 echo "Add, move, and creation of a directory deleted"
	echo "Press any key to continue"
	read
	echo "$CLEAR"
	;;
			 n) clear
	echo "Please contact me if this was incorrect."
	echo "Press any key to return to the main menu"
	read
	echo "$CLEAR"
	;;
#
#
4) clear
	echo "This option is currently under construction"
	echo "Please press any key"
	read
	;;
#
#
		5) clear
	echo "Please press 1 to continue or 2 to return to the main menu"
	read AN
		 case $AN in
	1) echo "Thank you!"
	 echo "Press any key to exit"
	 read
	 exit
	 ;;
		 2) clear
	 echo "$CLEAR"
	 ;;
		 *) echo "Input error please use 1 or 2, press any key to return"
	 echo "to the main menu"
	 echo "$CLEAR"
	 ;;
		*) clear
	echo "Invalid response, Please use a given choice (1,2,3,4,5)"
	echo "Please press any key to continue"
	read
	;;
	 esac
esac
esac
done

Last edited by GutterPunk; Sep 22, 2004 at 11:18 AM.
GutterPunk is offline   Reply With Quote
Old Sep 22, 2004, 09:02 PM   #9
BSD SMASH!
 
Malus's Avatar
 
Join Date: May 2002
Location: A rabbit hole. . .
Posts: 1,170
Rep Power: 0
Malus is on a distinguished road

esac closes a case statement.
Malus is offline   Reply With Quote
Old Sep 22, 2004, 11:07 PM   #10
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

Well yeah, but when i close it within my menu option then nothing works.

as you can see i have esac there, but the problems i am having are weird.
GutterPunk is offline   Reply With Quote
Old Sep 23, 2004, 12:53 AM   #11
BSD SMASH!
 
Malus's Avatar
 
Join Date: May 2002
Location: A rabbit hole. . .
Posts: 1,170
Rep Power: 0
Malus is on a distinguished road

Quote:
Originally Posted by GutterPunk
Well yeah, but when i close it within my menu option then nothing works.

as you can see i have esac there, but the problems i am having are weird.
I don't think you have an esac to close the nested case (in reference to the $ANS one with the options y and n).

Last edited by Malus; Sep 23, 2004 at 01:48 AM.
Malus is offline   Reply With Quote
Old Sep 23, 2004, 12:27 PM   #12
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

If there is an esac there it just causes a bunch more problems
GutterPunk is offline   Reply With Quote
Old Sep 23, 2004, 09:37 PM   #13
I = Greatest Dood
 
GutterPunk's Avatar
 
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
GutterPunk will become famous soon enough

woohoo got it fixed, now it is only not recognizing the astrick *
GutterPunk is offline   Reply With Quote
 

 
Powered by: vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
vBulletin implementation by Craig '5320' Humphreys

All times are GMT -5. The time now is 08:34 PM. Copyright ©2008 HeavenMedia.net