bash - Menu and Sub Menu and back to Menu Scripting On Linux -


Hello, I need a scripting script in some scripts that have the menus and sub menus in my script

1. Do something. 2. Do something. 3. Do something

When I select number 1 and press Enter then the sub menu will appear

1.do something <
2. Do something - 99.back in the menu

How can I make this and my biggest problem when press 99 when the menu can return

Try sample script : I used to select menu (1 and 2) loop. Note: Select the loop in the Bash for your options to sort the bullet # in order so that you need to echo the bullet # 99, then it will do something for you (a good home work for you) You have to come up with or you can finalize the value as the menu variable ".. 99_back_to_menu_1".

For the internal selection menu 2 loop, I use the loop (well to exit the internal selection loop, if the user selects: back_to_menu_1 option) In the menu, they will be prompted again for the menu again.

If you want you can comment to the loop (line #s, 18, 19 and 31). Menu_1 exits only when the user selects "Exit" to exit

  #! / Bin / bash ## Let's say that menu 1 for menu 1 and menu 2 have all your input in menu 2 # # If input data is in a file, then do this: menu1 = "$ (cat menu_1) "And with the cat menu_2 file for menu 2 or you can set the menu or menu 2 values ​​(different from the spaces): menu_1 =" giga koba fifa "; Menu_2 = "shenzi ed" ## says that you have Menu_1 = "Menu_1_a Menu_1_b Menu_1_c exit" menu_2 = "Menu_2_i Menu_2_ii Menu_2_iii Menu_2_iv back_to_menu1" select M1 in $ {menu_1}; What to do [[-n $ {m1}]]; Then echo-e "\ n- Menu 1: You chose: \" $ {m1} \ "\ n" if [["$ m1" == "exit"]]; Then break it; Fi ## External Selection Break by loop, if the user selects "Exit" to exit the external selection loop. ## -------- Internal / Second Select Loop ------------- Start [["$ m2" == "back_to_menu1"]; Choose M2 in $ {Menu_2}; What to do [[-n $ {m2}]]; Then Echo-A "\ n- Menu 2: You chose: \" $ {m2} \ "--- OK, do something for this selection in Menu 2. \ n" echo -e "\\ n \ n \ T - Okay, I did something for the $ m2 option ... ... well \ n \ n \ n "; If [["$ m2" == "back_to_manu1"]]; Then break it; Fi ## External Selection Break by loop, if the user selects "Exit" to exit the external selection loop. break; ## Break the internal selection with a loop as soon as the user selects a value. Else echo -e "\ n- invalid selection \" $ {REPLY} \ "... please try again. \ N \ n"; # # - - - Internal / second select loop ------------- Close and echo-e "N-Invalid selection \" $ {REPLY} \ "... Please try again. \ N \ n";  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -