The shell implements multi-level menu scripting example code
Step 1: Tips
This script mainly realizes the multi-level menu effect, and does not install the LAMP and LNMP environment. If you want to deploy the LNMP and LAMP environment in the actual generation environment, you only need to make a simple modification.
2. Presentation effect
2.1. First-level menu
2.2. Secondary Menu
2.3. Perform operations
3. Refer to the code
[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 # Add 1 here to determine whether the input is an integer. if [$? -ne 0] then # If it is not zero, the input is not an integer. 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 install httpd yum install httpd -y &> /dev/null if(($?==0)) then echo "Install httpd successfully" fi sleep 2 lamp_menu;; 2) # yum install mysql -y &> /dev/null if(($?==0)) then echo "Install mysql successfully" fi sleep 2 lamp_menu;; 3) # yum install php -y &> /dev/null if(($?==0)) then echo "php installed successfully" 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 # Add 1 here to check whether the input is an integer. if [$? -ne 0] then # If it is not zero, the input is not an integer. 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 yum install nginx -y &> /dev/null if(($?==0)) then echo "nginx installed successfully" fi sleep 2 lnmp_menu;; 2) # yum install mysql -y &> /dev/null if(($?==0)) then echo "Install mysql successfully" fi sleep 2 clear lnmp_menu;; 3) # yum install php -y &> /dev/null if(($?==0)) then echo "Install php successfully" 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 # Add 1 to determine if the input is an integer. If [0] $? - can then # if it is not equal to zero, on behalf of the input is not an integer. The echo "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" echo "| Waring!!! |" echo "|Please Enter Right Choice! | "echo" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - "sleep 1 elif [4] $num1 - gt then # input Numbers make 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
To this article about the shell to achieve multi-level menu scripting example code is introduced to this article, more related shell multi-level menu content please search the script home previous articles or continue to browse the following related articles hope that you will support the script home in the future!
Related article
-
The meaning and usage examples of set and shopt command options in the Shell
This article mainly introduces the relevant information about the meaning and use of set and shopt command options in the Shell. The article introduces it in great detail through the example code, which has certain reference value for everyone's study or work. The friends who need it will learn together with Xiaobian below.2017-09-09 -
Export json data to csv using a command line (one command does it)
This article mainly introduces the use of command line json data export to csv, a line of command to solve the method of detailed explanation, friends in need can use for reference, I hope to be helpful, I wish you a lot of progress, early promotion and pay rise2024-01-01 -
Use of the test command in Bash
This article mainly introduces the use of Bash test command, the article through the example code is very detailed, for everyone's study or work has a certain reference learning value, the need for friends to learn together with the small series2023-02-02 -
This section describes how to use the nmcli command in Linux
nmcli is a command line tool in the Linux system, used to manage network connections, it can help users configure and manage network connections, network devices and network connection properties, this article gives you a detailed introduction to the Linux nmcli command use method, need friends can refer to the next2024-03-03 -
The shell implements four simple methods of operation
When I just learned to write shell batch processing, logical operations, it is necessary to carry out the basic: four operations, here to talk about a simple implementation method in the linux shell2014-03-03 -
Build VSftpd service based on virtual user
This article mainly introduces the establishment of VSftpd services based on virtual users related information, the need of friends can refer to the next2015-09-09 -
shell scripts share the ssh automatic login function
mac did not find a good similar secureCRT, I wrote an automatic login script, share it, if it is Sina, you can use it directly without modifying the code2014-04-04 -
The shell script contains parameters with Spaces
This article mainly introduces the shell script parameters including Spaces, the article through the example code is very detailed, for everyone's study or work has a certain reference learning value, the need for friends to learn together with the small series2023-03-03
Latest comments