linux:shell:menu_bash
Linux
Menu interactif bash
Exemple
Code
menu.sh
function ligne_menu() { choix=$1 texte=$2 if [ "${choix}" == "0" ]; then printf "\t\t\t| %-50s|\n" "${texte}" else printf "\t\t\t| \033[30;47m%2s\033[00m %-47s|\n" "${choix}" "${texte}" fi } function affiche_rouge() { printf "\033[1;31;40m%s\033[00m\n" "$1" } function pause() { echo "" read -p "Appuyer sur ENTREE pour continuer ..." } while clear echo -e "\t\t\t ________________________________________________" echo -e "\t\t\t| |" echo -e "\t\t\t| MENU |" echo -e "\t\t\t|________________________________________________|" ligne_menu "0" "" ligne_menu "1" "Choix 1" ligne_menu "2" "Choix 2" ligne_menu "0" "" ligne_menu "0" " [Q]uitter" echo -e "\t\t\t|________________________________________________|" echo -en "\t\t\t\t\t\tChoix > " read REPLY test $REPLY do echo "" case $REPLY in 1) # Actions Choix 1... pause ;; 2) # Actions Choix 2... pause ;; q|Q) # Quitter clear break ;; *) affiche_rouge "!!! Choix invalide !!!" pause ;; esac done
linux/shell/menu_bash.txt · Dernière modification : 2022/11/20 14:17 de zandor