shell實(shí)現(xiàn)多級菜單腳本編寫的示例代碼
1. 提示
本腳本主要實(shí)現(xiàn)多級菜單效果,并沒有安裝LAMP、LNMP環(huán)境,如果要用在實(shí)際生成環(huán)境中部署LNMP、LAMP環(huán)境,只需要簡單修改一下就可以了。
2. 演示效果
2.1. 一級菜單
2.2. 二級菜單
2.3. 執(zhí)行操作
3. 參考代碼
[root@server ~]# vim multi_menu.sh #!/bin/bash # function menu(){ cat << EOF ---------------------------------------------- |*******Please Enter Your Choice:[1-4]*******| ---------------------------------------------- * `echo -e "\033[35m 1)lamp install\033[0m"` * `echo -e "\033[35m 2)lnmp install\033[0m"` * `echo -e "\033[35m 3)quit\033[0m"` * `echo -e "\033[35m 4)return main menu\033[0m"` EOF } function lamp_menu(){ cat << EOF ---------------------------------------------- |*******Please Enter Your Choice:[1-4]*******| ---------------------------------------------- * `echo -e "\033[35m 1)http install\033[0m"` * `echo -e "\033[35m 2)mysql install\033[0m"` * `echo -e "\033[35m 3)php install\033[0m"` * `echo -e "\033[35m 4)return main menu\033[0m"` EOF read -p "####please input second_lamp optios[1-4]: " num2 expr $num2 + 1 &>/dev/null #這里加1,判斷輸入的是不是整數(shù)。 if [ $? -ne 0 ] then #如果不等于零,代表輸入不是整數(shù)。 echo "###########################" echo "Waing !!!,input error " echo "Please enter choose[1-4]:" echo "##########################" sleep 1 else if [ $num2 -gt 4 ] then echo "###########################" echo "Waing !!!,Out of range " echo "Please enter choose[1-4]:" echo "##########################" sleep 1 fi fi case $num2 in 1) # yum 安裝httpd yum install httpd -y &> /dev/null if(($?==0)) then echo "安裝httpd成功" fi sleep 2 lamp_menu ;; 2) # yum 安裝 MySQL... yum install mysql -y &> /dev/null if(($?==0)) then echo "安裝mysql成功" fi sleep 2 lamp_menu ;; 3) # yum 安裝 PHP... yum install php -y &> /dev/null if(($?==0)) then echo "安裝php成功" fi sleep 2 lamp_menu ;; 4) clear menu ;; *) clear echo echo -e "\033[31mYour Enter the wrong,Please input again Choice:[1-4]\033[0m" lamp_menu esac } function lnmp_menu(){ cat << EOF ---------------------------------------------- |*******Please Enter Your Choice:[1-4]*******| ---------------------------------------------- * `echo -e "\033[35m 1)nginx install\033[0m"` * `echo -e "\033[35m 2)mysql install\033[0m"` * `echo -e "\033[35m 3)php install\033[0m"` * `echo -e "\033[35m 4)return main menu\033[0m"` EOF read -p "please input second_lnmp options[1-4]: " num3 expr $num3 + 1 &>/dev/null #這里加1,判斷輸入的是不是整數(shù)。 if [ $? -ne 0 ] then #如果不等于零,代表輸入不是整數(shù)。 echo "###########################" echo "Waing !!!,input error " echo "Please enter choose[1-4]:" echo "##########################" sleep 1 else if [ $num3 -gt 4 ] then echo "###########################" echo "Waing !!!,Out of range " echo "Please enter choose[1-4]:" echo "##########################" sleep 1 fi fi case $num3 in 1) # yum 安裝 Nginx... yum install nginx -y &> /dev/null if(($?==0)) then echo "安裝nginx成功" fi sleep 2 lnmp_menu ;; 2) # yum 安裝 MySQL... yum install mysql -y &> /dev/null if(($?==0)) then echo "安裝mysql成功" fi sleep 2 clear lnmp_menu ;; 3) # yum 安裝 PHP... yum install php -y &> /dev/null if(($?==0)) then echo "安裝php成功" fi sleep 2 clear lnmp_menu ;; 4) clear menu ;; *) clear echo echo -e "\033[31mYour Enter the wrong,Please input again Choice:[1-4]\033[0m" lnmp_menu esac } clear menu while true do read -p "##please Enter Your first_menu Choice:[1-4] " num1 expr $num1 + 1 &>/dev/null #這里加1,判斷輸入的是不是整數(shù)。 if [ $? -ne 0 ] then #如果不等于零,代表輸入不是整數(shù)。 echo "----------------------------" echo "| Waring!!! |" echo "|Please Enter Right Choice!|" echo "----------------------------" sleep 1 elif [ $num1 -gt 4 ] then # 輸入數(shù)字超范圍 echo "----------------------------" echo "| Waring!!! |" echo "| Out of range! |" echo "----------------------------" sleep 1 else case $num1 in 1) clear lamp_menu ;; 2) clear lnmp_menu ;; 3) clear break ;; 4) clear menu ;; *) clear echo -e "\033[31mYour Enter a number Error,Please Enter again Choice:[1-4]: \033[0m" menu esac fi done
到此這篇關(guān)于shell實(shí)現(xiàn)多級菜單腳本編寫的示例代碼的文章就介紹到這了,更多相關(guān)shell 多級菜單內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
慎用rm -rf /與 rm -rf /* 推薦使用mv代替rm
本文主要介紹了慎用rm -rf /與 rm -rf /* 推薦使用mv代替rm,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10Shell腳本統(tǒng)計(jì)文件行數(shù)的8種方法
這篇文章主要介紹了Shell腳本統(tǒng)計(jì)文件行數(shù)的8種方法,本文講解了獲取單個(gè)文件行數(shù)、獲取特定目錄所有文件的行數(shù)兩種需求共計(jì)8種方法,需要的朋友可以參考下2015-03-03使用Linux shell腳本實(shí)現(xiàn)FTP定時(shí)執(zhí)行批量下載指定文件
使用FTP定時(shí)批量下載指定文件的shell腳本,具體實(shí)例介紹如下所示,需要的朋友參考下吧2017-04-04shell腳本轉(zhuǎn)發(fā)80端口數(shù)據(jù)包給Node.js服務(wù)器
開發(fā)基于Node.js的WEB應(yīng)用很方便,但是服務(wù)端口問題,由于Linux內(nèi)核規(guī)定普通用戶只能使用大于1024的端口號,所以使用普通用戶運(yùn)行Node.js服務(wù)就不80端口2014-03-03Linux下shell腳本監(jiān)控Tomcat的狀態(tài)并實(shí)現(xiàn)自動啟動的步驟
這篇文章主要介紹了Linux下shell腳本監(jiān)控Tomcat的狀態(tài)并實(shí)現(xiàn)自動啟動的步驟,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-12-12Linux tar 命令出現(xiàn) Cowardly refusing to create an empty archive
這篇文章主要介紹了Linux tar 命令出現(xiàn) Cowardly refusing to create an empty archive 錯誤解決辦法的相關(guān)資料,需要的朋友可以參考下2017-04-04