语法
case word in |
command-list 后面的 ;;
其实还可以换成 ;&
和 ;;&
, 它们有什么区别呢 ?
实例 ;&
;&
是在匹配到 pattern 后, 继续执行 next clause 的 command-list, 比如脚本:
ANIMAL=$1 |
结果:
➜ ./foo horse |
如上 (4)
会在 four
之后出现.
实例 ;;&
;;& 表示 as if the pattern list had not matched before
.
ANIMAL=$1 |
结果:
➜ ./foo horse |
可以看到 :
dog 会输出 four
和 an unknown number or size of
, ;;&
会把 dog 当作没有匹配到而继续往下进行匹配.
horse 会输出 four
和 big
.
实例 ;;
把上面的 ;;&
改为 ;;
后, 则匹配到之后退出 case 块:
➜ ./foo horse |