case语句:选择结构
case switch(变量值) in
value1)
statement
...
;;
value2
statement
...
;;
*)
statement
...
;;
esac
例:输入随便输入一个字符判断字符类型。
1 #!/bin/bash
2 #
3 case $1 in
4 [0-9])
5 echo "A Digit." ;;
6 [a-z])
7 echo "Lower." ;;
8 [A-Z])
9 echo "Upper." ;;
10 *)
11 echo "特殊字符。" ;;
12 esac
例2:只接受参数start,stop,restart,status其中之一
#!/bin/bash
case $1 in
start)
echo "start server...";;
'stop')
echo "stop server...";;
'restart')
echo "restarting server...";;
'status')
echo "running...";;
*)
echo "'basname $0' {start | stop | restart | status}";;
esac
转载于:https://blog.51cto.com/10868195/2047806