**
Select循环语句
**
(死循环,加入break或exit退出死循环) 常见操作是实现菜单功能
语法:
-----------------------------------------------------
select i in 命令1 命令2 ... //相当于read -p循环设置描述信息
do
command
done
退出整个循环
break
exit
注意:输入值为序号
-------------------------------------------------------------------------------
[root@manage shell]# vim s.sh
#!/bin/bash
select i in a b c
do
case $i in
a)
yum -y install httpd
;;
b)
de=`rpm -qa | grep httpd`
rpm -e --nodeps $de
;;
c)
systemctl start httpd
;;
*)
systemctl status httpd
;;
esac
done
-------------------------------------------------------------------------------
[root@manage shell]# ./s.sh
-------------------------------------------------------------------------------
1) a
2) b
3) c
#? 1
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirrors.shu.edu.cn
* updates: mirrors.zju.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-80.el7.centos.1 将被 安装
-------------------------------------------------------------------------------
实例
-----------------------------------------------------
[root@node1 ~]# vim sl.sh
#!/bin/bash
#a=`cat /etc/passwd`
select i in `free -g`
do
uname -r
break
done
[root@node1 ~]# ./sl.sh
1) total 5) buff/cache 9) 0 13) 0 17) 1
2) used 6) available 10) 0 14) Swap:
3) free 7) Mem: 11) 0 15) 1
4) shared 8) 0 12) 0 16) 0
#? dsa //输入任何值,都能执行
3.10.0-514.el7.x86_64
举例
# vim wml.sh
select i in a b c d
do
cat /etc/passwd
break
done
# sh wml.sh