标签:
#case ..esac语句:与switch ..case类似,是一种多分支选择结构
#case语句匹配一个值或一个模式,如果匹配成功执行相应命令,如果匹配不成功执行*命令
#;;与break类似,代表跳到整个case语句的最后
#case 值 in
#模式1)
# command1
# ;;
#模式2)
# command1
# ;;
#*)
# command1
# ;;
#esac
#示例如下:
1 echo ‘Input a number between 1 to 4‘ 2 echo -e ‘Your number is:\c‘ 3 read aNum 4 case $aNum in 5 1) echo ‘You select 1‘ 6 ;; 7 2) echo ‘You select 2‘ 8 ;; 9 3) echo ‘You select 3‘ 10 ;; 11 4) echo ‘You select 4‘ 12 ;; 13 *) echo ‘You do not select a number between 1 to 4‘ 14 ;; 15 esac
#测试输入xxx.sh -f index.html or xxx.sh -d unix 此时进入×)输出
1 option="${1}" 2 case ${option} in 3 -f) FILE="${2}" 4 echo "File name is $FILE" 5 ;; 6 -d) DIR="${2}" 7 echo "Dir name is $DIR" 8 ;; 9 *) 10 echo "`basename ${0}`:usage: [-f file] | [-d directory]" #如果都不是,则执行xxx.sh# 11 exit 1 # Command to come out of the program with status 1 12 ;; 13 esac
Linux Gvim shell case...esac语句
标签:
原文地址:http://www.cnblogs.com/blog4matto/p/5572031.html