一、簡單的多級菜單 顯示效果如下: ...
一、簡單的多級菜單
[root@web129 ~]# cat menu.sh #!/bin/bash #shell菜單演示 function menu() { echo -e `date` cat <<EOF ----------------------------------- >>>菜單主頁: `echo -e "\033[35m 1)系統狀態\033[0m"` `echo -e "\033[35m 2)服務管理\033[0m"` `echo -e "\033[35m 3)主菜單\033[0m"` `echo -e "\033[35m Q)退出\033[0m"` EOF read -p "請輸入對應序列號:" num1 case $num1 in 1) echo -e "\033[32m >>>系統狀態-> \033[0m" system_menu ;; 2) echo -e "\033[32m >>>服務管理-> \033[0m" server_menu ;; 3) echo -e "\033[32m >>>返回主菜單-> \033[0m" menu ;; Q|q) echo -e "\033[32m--------退出--------- \033[0m" exit 0 ;; *) echo -e "\033[31m err:請輸入正確的編號\033[0m" menu esac } function system_menu() { cat<<EOF ------------------------ ********系統狀態******** ------------------------ 1)nginx 狀態 2)http 狀態 3)tomcat 狀態 X)返回上一級目錄 ------------------------ EOF read -p "請輸入編號:" num2 case $num2 in 1) `echo -e "systemctl status nginx.service"` system_menu ;; 2) `echo -e "systemctl status httpd.service"` system_menu ;; 3) `echo -e "systemctl status tomcat.service"` system_menu ;; x|X) echo -e "\033[32m---------返回上一級目錄------->\033[0m" menu ;; *) echo -e "請輸入正確編號" system_menu esac } function server_menu() { cat<<EOF ------------------------ 1)開啟服務 2)停止服務 X)返回上一級目錄 ------------------------ EOF read -p "請輸入編號:" num3 case $num3 in 1) op_menu ;; 2) op_menu1 ;; x|X) echo -e "\033[32m-- -----返回上一級目錄---------> \033[0m" menu ;; *) echo -e "請輸入正確編號" system_menu esac } function op_menu() { cat<<EOF ------------------------ 1)開啟nginx服務 2)開啟http服務 3)開啟tomcat服務 X)返回上一級目錄 ------------------------ EOF read -p "請輸入編號:" num4 case $num4 in 1) `echo -e "systemctl start nginx.service"` op_menu ;; 2) `echo -e "systemctl start httpd.service"` op_menu ;; 3) `echo -e "systemctl start tomcat.service"` op_menu ;; x|X) echo -e "\033[32m--------返回上一級目錄------->\033[0m" server_menu ;; *) echo -e "請輸入正確編號" op_menu esac } function op_menu1() { cat<<EOF ------------------------ 1)停止nginx服務 2)停止http服務 3)停止tomcat服務 X)返回上一級目錄 ------------------------ EOF read -p "請輸入編號:" num5 case $num5 in 1) `echo -e "systemctl stop nginx.service"` op_menu1 ;; 2) `echo -e "systemctl stop httpd.service"` op_menu1 ;; 3) `echo -e "systemctl stop tomcat.service"` op_menu1 ;; x|X) `echo -e "\033[32m >>>返回上一級目錄---> \033[0m"` server_menu ;; *) echo -e "請輸入正確編號" op_menu1 esac } menu [root@web129 ~]#
顯示效果如下: