linux bash shell中case语句的实例
网络编程
bash case语句的例子。
分享一段bash shell代码,对于学习bash的同学理解case语句的用法,会有帮助。
例子:
#!/bin/bash
##
# Program:
# File operation
# 1.) Open file 2.) Display file 3.) Edit file 4.) Delete file
# site: WWW.gimoo.net
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo "---------------------------------"
echo "List of item to operate file -"
echo "---------------------------------"
echo "1). Open a file -"
echo "2). Display a file -"
echo "3). Edit a file -"
echo "4). Delete a file -"
echo "---------------------------------"
read select
case $select in
1)
echo "do open file operation"
2)
echo "do display a file operation"
3)
echo "do edit a file operation"
4)
echo "do delete a file operation"
*)
echo "There is nothing to do!"
exit 1
esac
shell中case的用法学习笔记
shell中的case语句:可以把变量的内容与多个模板进行匹配,再根据成功匹配的模板去决定应该执行哪部分代码。使用格式:case匹配母板in模板1[|模板2]…)
一个shell for循环与case结合的脚本(监控程序状态)
核心代码:#/bin/bashset-xHOSTS="nginxmysqlphp-cgi"formyhostin$HOSTSdocount=(`psaux|grep$myhost|grep-vgrep|wc-l`)echo"$myhost"echo"$count"if[$count-eq0];thencase$myhostinnginx)cd/usr/local/webserv
shell脚本中case条件控制语句的一个bug分析
在shell脚本中,发现case语句的一个问题。就是指定小写字母[a-z]和大写字母[A-Z]的这种方法不管用了。出现如下情况:[root@station1~]#catcase.sh#!/bin/bashwhile:do
编辑:一起学习网
标签:语句,模板,脚本,代码,母板