LinuxCommandLine -- [脚本 - case]

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
LinuxCommandLine -- [脚本 - case]_第1张图片

你可能感兴趣的:(LinuxCommandLine -- [脚本 - case])