helping me in a bash script that perform a "select" menus Task
hello all .... ,
i want to make a bash script that controls the action of the logs and some services by using menus and i want it to be something like that starts with that form : 1) mysql 2) system 3) apache 4) quit Please Select a Choice Or For The Menu : when the user enter a choice he will redirect to another menu for example if the user type 1 which is for mysql service this menu will appear 1) mysql-log 2) mysql-start 3) mysql-stop 4) mysql-restart and every choice of that perform a certain function like mysql start , restart , stop and so on i write this script Code:
#!/bin/bash but i got errors >> 1-i cannot choose another option except the choice 1 which is mysql service if i choose another service nothing happened !!!! Code:
2-if i choose the first item 1.)mysql it works and all the items listed in the mysql item work well but at the same time i cannot get back to the other option so how i can add a back option and sorry for the long thread Thanks For ALL |
If you indent your code you'll find it much easier to see where things are going wrong.
Code:
#!/bin/bash |
thanks for you help it finally works :)
what is the break 2 and break 1 means / ? i know that break "only" alter the execution of the loop what about break 1 and 2 ? ... but how i can make that ? > -if i choose the first item 1.)mysql it works and all the items listed in the mysql item work well but at the same time i cannot get back to the other option so how i can add a back option how can i make a back option to return to the main menu ? .. |
Your script has three loops nested inside each other:
Code:
level 1 'while true; do ... done' If you are in level 3 and you want to get back to the main menu you need to break out of 2 loops by using 'break 2'. If you are in level 2 and you want to get back to the main menu you need to break out of 1 loop by using 'break 1'. ('break' means exactly the same as 'break 1') I'm sorry, but I don't understand the rest of your question. |
thanks for your great support ,, really thanks
all i meant that i want to add to every menu another "back" option so that i can out from any menu to the higher level menu u mean that will done by using break so if i want to get out of the if condition 2 to the one i will use break 1 and so on ? thanks for your help |
The problem is that the menu on level 3 is only accessed through an if/then condition test, so you can't redisplay its menu without going back to the main menu and selecting 'mysql' again.
One solution is to add yet another loop :) So now your script has four loops nested inside each other: Code:
level 1 'while true; do ... done' Code:
#!/bin/bash |
All times are GMT -5. The time now is 05:05 PM. |