总的来说,case是一个判断语句 ,比if更加容易理解一点。@H_502_2@
case 语句格式@H_502_2@
case in 变量 值1) 内容 ;; 值2) 内容 ;; esac
注意:每个内容后面都需要添加 ;; ,可以跨行也可以同行写。@H_502_2@
#!/bin/bash - # 打印选择菜单 cat <<EOF Option: 1) restart networking service. 2) start networking service. 3) stop networking service. *) exit. EOF read -p "Please enter a option:" number # 使用case语句对参数进行判断 case $number in 1) echo "The Networking service is restart,wait......" ;; 2) echo "The Networking service is start,wait......" ;; 3) echo "The Networking service is stop,wait......" ;; *) echo "exit." ;; esac
[root@XiaoPeng scripts]# bash case.sh
Option:
1) restart networking service.
2) start networking service.
3) stop networking service.
*) exit.
Please enter a option:1
The Networking service is restart,wait......@H_502_2@
版权所有:arppinging@H_502_2@