LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux menu won't work - case statement (https://www.linuxquestions.org/questions/linux-newbie-8/linux-menu-wont-work-case-statement-909304/)

Batistuta_g_2000 10-21-2011 04:14 AM

Linux menu won't work - case statement
 
Can anyone help me, am new to linux have menu to pick from three options; i want it to close and load another shell script if option one or two - else exit:


#!/bin/sh
#
############## Menu for Backup and Restore Options ######################
#
while :
do
clear
echo "_______________________________________"
echo " MAIN BACK MENU "
echo "_________________________________________"
echo " "
echo " [1] Backup a File or Directory"
echo " [2] Restore a File or Directory"
echo " [3] Exit"
echo " "
echo "_________________________________________"
echo " "
echo " "
echo " "
echo -n "Enter your menu choice [1-3]"
read yourch

case $yourch in




1)
clear


echo "________________________________"
echo "_______BACKUP MENU_____________"
echo ""
cd /home/ubuntu/
backup start ;read;;

2)
clear


echo "________________________________"
echo "_______RESTORE MENU_____________"
echo ""
cd /home/ubuntu/
restore ;read;;



3) exit 0 ;;
*) echo "Opps! Please select an option 1,2 or 3";
echo "Press a key..."; read ;;
esac




done

phaemon 10-21-2011 04:36 AM

Well, you haven't said what isn't working or what you're trying to do (that's why you should have comments in your script!), but I'm guessing it doesn't run the "backup" or the "restore" scripts, which are ones that are in your /home/ubuntu directory?

You probably need to have the full path, so rather than using "cd", just run "/home/ubuntu/backup" and "/home/ubuntu/restore"

Also, why do you have a "read" after? Don't you just want to exit after they've chosen a valid option?

jv2112 10-21-2011 04:36 AM

You can embed it in the script or set the path to the next script in the script.

grail 10-21-2011 04:56 AM

May I also suggest having a look at what a here document is and maybe also select.

David the H. 10-21-2011 05:59 AM

Does this have to be a posix-compliant script (#!/bin/sh), or can you use bash or another shell? It affects what features can and can't be used.

Also please use [code][/code] tags around your code, to preserve formatting and to improve readability. (And note that quote tags are not for code either.)


All times are GMT -5. The time now is 03:34 AM.