Linux Basic — Full CLI Menu
Full CLI Menu
This page shows a complete, modular menu structure suitable for small admin tools. It uses select for the main choices and functions for each action.
Example Structure
#!/usr/bin/env bash
set -euo pipefail
RED="\e[31m"; GREEN="\e[32m"; RESET="\e[0m"
main_menu() {
PS3="Choose: "
select opt in "Start" "Stop" "Status" "Config" "Quit"; do
case "$REPLY" in
1) start_service;;
2) stop_service;;
3) status_service;;
4) config_menu;;
5) echo "Bye"; exit 0;;
*) echo "invalid";;
esac
done
}
start_service() { echo -e "${GREEN}Starting...${RESET}"; }
stop_service() { echo -e "${RED}Stopping...${RESET}"; }
status_service(){ echo "All good"; }
config_menu() { echo "Config submenu"; }
trap 'echo; echo "exiting"; exit' INT
main_menu
Break actions into functions for testability and unit-like modularity.
Next → Sub-Menus