shell实现多级菜单脚本编写的示例代码

2024-04-18 0 496
目录
  • 1. 提示
  • 2. 演示效果
    • 2.1. 一级菜单
    • 2.2. 二级菜单
    • 2.3. 执行操作
  • 3. 参考代码

    1. 提示

    本脚本主要实现多级菜单效果,并没有安装LAMP、LNMP环境,如果要用在实际生成环境中部署LNMP、LAMP环境,只需要简单修改一下就可以了。

    2. 演示效果

    2.1. 一级菜单

    shell实现多级菜单脚本编写的示例代码

    2.2. 二级菜单

    shell实现多级菜单脚本编写的示例代码

    2.3. 执行操作

    shell实现多级菜单脚本编写的示例代码

    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,判断输入的是不是整数。
    if [ $? -ne 0 ]
    then #如果不等于零,代表输入不是整数。
    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,判断输入的是不是整数。
    if [ $? -ne 0 ]
    then #如果不等于零,代表输入不是整数。
    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,判断输入的是不是整数。
    if [ $? -ne 0 ]
    then #如果不等于零,代表输入不是整数。
    echo \”—————————-\”
    echo \”| Waring!!! |\”
    echo \”|Please Enter Right Choice!|\”
    echo \”—————————-\”
    sleep 1
    elif [ $num1 -gt 4 ]
    then # 输入数字超范围
    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

    shell实现多级菜单脚本编写的示例代码

    shell实现多级菜单脚本编写的示例代码

    shell实现多级菜单脚本编写的示例代码

    到此这篇关于shell实现多级菜单脚本编写的示例代码的文章就介绍到这了,更多相关shell 多级菜单内容请搜索悠久资源网以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源网!

    您可能感兴趣的文章:

    • Shell实现多级菜单系统安装维护脚本实例分享

    收藏 (0) 打赏

    感谢您的支持,我会继续努力的!

    打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
    点赞 (0)

    悠久资源 linux shell shell实现多级菜单脚本编写的示例代码 https://www.u-9.cn/jiaoben/linuxshell/186926.html

    常见问题

    相关文章

    发表评论
    暂无评论
    官方客服团队

    为您解决烦忧 - 24小时在线 专业服务