Shell implementation of multi-level menu scripting

Source: Internet
Author: User

This article mainly introduces the shell implementation of multi-level menu system Installation script instance sharing, this script with multi-level menu to achieve lamp, LNMP installation display effect, the need for Friends can refer to:

Hint: This script mainly realizes multi-level menu effect, and does not install lamp, LNMP environment, if want to use in the actual build environment to deploy LNMP, lamp environment, only need to make a simple modification.


Demo Effect:

1. Level menu

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/8C/69/wKioL1hsVUyjqmWsAAASz-o0joA283.png "title=" level menu alt= "Wkiol1hsvuyjqmwsaaasz-o0joa283.png"/>

2, Level two menu

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/8C/6D/wKiom1hsVtHhwMV-AAASZwYejKg413.png "title=" Level two menu " alt= "Wkiom1hsvthhwmv-aaaszwyejkg413.png"/>

3. Perform operation

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/8C/6D/wKiom1hsWFvAjE1uAABbFtiPd4Y529.png "title=" 2017-01-04_095931.png "alt=" Wkiom1hswfvaje1uaabbftipd4y529.png "/>

Script reference:

The code is as follows:
#!/bin/bash#[ -f /etc/init.d/functions ] && . /etc/init.d/ Functionsfunction 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 &NBSP;2) mysql install\033[0m "' *&Nbsp;   ' echo -e  "\033[35m 3) php install\033[0m" ' *    ' echo -e   "\033[35m 4" return main menu\033[0m "' eofread -p " # # #please  input  second_lamp optios[1-4]:  " num2expr  $num 2 + 1 &>/dev/null    #这里加1 to determine if the input is an integer. if [ $? -ne 0 ];then     #如果不等于零, representing input is not an integer.  echo  "###########################"  echo  "waing !!!, input error     " echo " please enter choose[1-4]: " echo " ########################## "  exit 1ficase  $num 2 in  1)    action  "installed httpd ..."  /bin/true   sleep 2   lamp_menu   ;; &NBSP;&NBSP;2)    action  "Installed mysql ..."  /bin/true   sleep  2   lamp_menu   ;;   3)    action  "installed php ..."  /bin/true   sleep  2   lamp_menu   ;; &NBSP;&NBSP;4)    clear   menu   ;;   *)    clear   echo    echo -e  "\033[ 31myour enter the wrong,please input again choice:[1-4]\033[0m "    lamp_menuesac}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 "' eofread -p " please input second_lnmp options[1-4]:  " num3expr   $num 2 + 1 &>/dev/null   #这里加1 to determine if the input is an integer. if [ $? -ne 0 ];then   #如果不等于零, representing input is not an integer.   echo   echo  "Please enter a integer"   exit  1ficase  $num 3 in   1)      action  "Installed nginx ... " /bin/true     sleep 2     lnmp_menu      ;; &NBSP;&NBSP;&NBSP;2)     action  "Installed mysql ..."  /bin/true     sleep 2    clear    lnmp_menu     ;;    3)      action  "installed php ..."  /bin/true      sleep 2     clear     lnmp_menu     ;; &NBSP;&NBSP;&NBSP;4)     clear    menu    ;;    *)     clear    echo    echo  -e  "\033[31myour enter the wrong,please input again choice:[1-4]\033[ 0m "    lnmp_menuesac}clearmenuwhile true ;d o read -p " # #please  enter your first_menu choice:[1-4] " num1  expr  $num 1 + 1  &>/dev/null    #这里加1 to determine if the input is an integer.   if [ $? -ne 0 ];then    #如果不等于零, representing input is not an integer.     echo  "----------------------------"     echo  "| "      waring!!!            | "     echo&nBSP; "| Please enter right choice!| "     echo  "----------------------------"     sleep 1    case  $num 1 in      1)         clear       lamp_menu       ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2)        clear        lnmp_menu       ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;3)        clear        break       ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;4)        clear        menu       ;;       *) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CLEAR&NBSP;&NBSP;&Nbsp;    echo -e  "\033[31myour enter a number error,please  enter again choice:[1-4]: \033[0m "              menu   esacdone







Shell implementation of multi-level menu scripting

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.