shell脚本中case select 的使用
#!/bin/bash
# case
echo "1.Install PHP"
echo "2.Install Mysql"
echo "3.Install Nginx"
read -p "please input your digit:" digit
case "$digit" in
"1" )
echo "Install PHP"
#输出两个分号
;;
"2" )
echo "Install Mysql"
;;
"3" )
echo "Install Nginx"
;;
* )
#其它输入
echo "Error"
;;
esac
运行结果
# sh case.sh
1.Install PHP
2.Install Mysql
3.Install Nginx
please input your digit:1
Install PHP
结合select做选择菜单。
#! /bin/bash
# case
PS3="Select your digit:"
select i in "Install PHP" "Install Mysql" "Install Nginx"
do
case $i in
"Install PHP" )
echo "Install PHP"
#输出两个分号
;;
"Install Mysql" )
echo "Install Mysql"
;;
"Install Nginx" )
echo "Install Nginx"
;;
* )
#其它输入
echo "Error"
;;
esac
done
执行的时候,必须用bash来执行。
# /bin/bash case.sh
1) Install PHP
2) Install Mysql
3) Install Nginx
Select your digit:1
Install PHP
Select your digit:2
Install Mysql
Select your digit:3
Install Nginx
Select your digit:4
Error
Select your digit:^C