|
| Notices |
DriverHeaven is currently recruiting for the AWOMO Beta Test / Elite Op Team. AWOMO is a digital download service for games, and we're looking to expand the beta team. If you're interested. Sign up as a member here at DriverHeaven and then head HERE to submit your details. Thanks
For more info on AWOMO visit their site HERE
Welcome to the DriverHeaven.net forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
 |
Sep 21, 2004, 03:03 PM
|
#1
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
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.
|
|
|
Sep 21, 2004, 09:15 PM
|
#2
|
|
BSD SMASH!
Join Date: May 2002
Location: A rabbit hole. . .
Posts: 1,170
Rep Power: 0
|
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.
|
|
|
Sep 21, 2004, 09:45 PM
|
#3
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
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).
|
|
|
Sep 22, 2004, 04:44 AM
|
#4
|
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,256
Rep Power: 0
|
Code:
Please use code tags as it makes things so much easier to read
|
|
|
Sep 22, 2004, 10:42 AM
|
#5
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
what do you mean code tags? lol
|
|
|
Sep 22, 2004, 10:47 AM
|
#6
|
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,256
Rep Power: 0
|
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)
|
|
|
Sep 22, 2004, 11:01 AM
|
#7
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
doh i got ya! ill post my new problem in a second, if you are willing to stand by your help is most appreciated
|
|
|
Sep 22, 2004, 11:07 AM
|
#8
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
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.
|
|
|
Sep 22, 2004, 09:02 PM
|
#9
|
|
BSD SMASH!
Join Date: May 2002
Location: A rabbit hole. . .
Posts: 1,170
Rep Power: 0
|
esac closes a case statement.
|
|
|
Sep 22, 2004, 11:07 PM
|
#10
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
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.
|
|
|
Sep 23, 2004, 12:53 AM
|
#11
|
|
BSD SMASH!
Join Date: May 2002
Location: A rabbit hole. . .
Posts: 1,170
Rep Power: 0
|
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.
|
|
|
Sep 23, 2004, 12:27 PM
|
#12
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
If there is an esac there it just causes a bunch more problems
|
|
|
Sep 23, 2004, 09:37 PM
|
#13
|
|
I = Greatest Dood
Join Date: Nov 2003
Location: PuNk
Posts: 5,854
Rep Power: 42
|
woohoo got it fixed, now it is only not recognizing the astrick *
|
|
|
|
|
|