美文网首页
LinuxCommandLine -- [脚本 - case]

LinuxCommandLine -- [脚本 - case]

作者: liaozb1996 | 来源:发表于2018-04-30 13:51 被阅读0次
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]

      本文链接:https://www.haomeiwen.com/subject/xwbzlftx.html