case test_variable in
pattern1 | pattern2) commands;;
pattern1 | pattern2) commands;;
*) commands;;
esac
-
test_varibale
对变量test_variable
进行判断 - pattern
通配符
-
;;
命中一条,执行对应代码块后退出 -
;;&
命中后继续判断
以 .py
结尾的文件,用 python 执行;
以 .sh
结尾的文件,用 bash 执行
其他文件,用 less 查看其内容
#!/bin/bash
shell=/bin/bash
python=/bin/python
case "$1" in
*.py) $python $1
;;
*.sh) $shell $1
;;
*) less $1
;;
esac

网友评论