In general, case is a judgment statement that is easier to understand than if.
Case Statement Format
case in 变量 值1) 内容 ;;值2) 内容 ;;esac
Note: Each content needs to be added after;; , can be written across rows or peers.
Instance: Executes the statement based on the selection entered by the user.
#!/bin/bash -# 打印选择菜单cat <<EOF Option: 1) restart networking service. 2) start networking service. 3) stop networking service. *) exit.EOFread -p "Please enter a option:" number# 使用case语句对参数进行判断case $number in1) 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
[Email protected] 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 ...
All rights reserved: Arppinging
"Shell" Linux Shell Case detailed