为什么bash中的通配符匹配在bash和source中得到不同的结果

  • 本文关键字:bash source 结果 通配符 bash
  • 更新时间 :
  • 英文 :


我有一个脚本case 11.2 in +([0-9])?(.+([0-9]))) echo aa;; *) echo bb;; esac

使用source test.sh时打印aa,但使用bash test.sh时返回错误

test.sh: line 1: syntax error near unexpected token `('
test.sh: line 1: `case 11.2 in +([0-9])?(.+([0-9])))  echo aa;;   *)  echo bb;; esac'

解决方法是使用bash -i。但为什么他们在互动和非互动模式下会得到不同的结果呢?

扩展的glob模式(+(...)?(...)+(...)等(需要设置extglobshell选项。在脚本开头添加shopt -s extglob

最新更新