Linux Basic — Sub-Menus
Sub-Menus
Nested menus let users drill into categories without cluttering the top-level menu. Each submenu should be a function that returns to the caller.
Example
config_menu() {
options=("Set host" "Set port" "Back")
PS3='config> '
select opt in "${options[@]}"; do
case "$REPLY" in
1) read -rp "Host: " host; ;;
2) read -rp "Port: " port; ;;
3) break;;
*) echo "invalid";;
esac
done
}
Because menus are functions, tests can call them with faked stdin.
Next → Dynamic Menus