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 |
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? |
You can embed it in the script or set the path to the next script in the script.
|
May I also suggest having a look at what a here document is and maybe also select.
|
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. |