creating submenus in bash
Hi all,
Trying to build a series of options in a bash script and im fine with 1 menu but i want to put a sub menu in one of the options... #!/bin/bash menu () { clear echo "-------------------------------" echo " M A I N - M E N U" echo " 1) option " echo " 2) option " echo " 3) option " echo " 4) option " echo "-------------------------------" while do read action case $action in "1") do something ;; "2") do something else ;; "3") submenu () { clear echo "-------------------------------" echo "SUB -MENU" echo "a) option" echo "b) option" echo "-------------------------------" while : do read subaction case $subaction in "a") do something ;; "b") do something else ;; esac done } submenu; ;; "4") echo "Bye!" exit 0 ;; *) echo "Error: Invalid option..." read -p "Press [Enter] key to continue..." readEnterKey ;; esac done } menu; but bash is complaining that there's a syntax error, can someone tell me how can i create in submenus in bash ? thanks, |
solved
Solved it
Hadnt added a ;; what i wrote is actually correct. Can see why its called bash... solution: 3) submenu () { clear echo "-------------------------------" echo "SUB -MENU" echo "a) option" echo "b) option" echo "-------------------------------" while : do read subaction case $subaction in "a") do something ;; "b") do something else ;; esac done } submenu; ;; 4) |
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
I recommend not putting the submenu function definition inside the main menu function. Functions are generally intended to be defined at the top of the script, so that they will be sitting in the environment ready to use when you need them. It also lessens the clutter, helping readability. Edit: Also, your first loop has an error: Code:
while #should be "while :" Code:
while true; do |
All times are GMT -5. The time now is 11:06 AM. |