" />

欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

shell實(shí)現(xiàn)多級菜單腳本編寫的示例代碼

 更新時(shí)間:2024年02月27日 08:28:52   作者:[禾火]  
本文主要介紹了shell實(shí)現(xiàn)多級菜單腳本編寫,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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)文章

最新評論