我有一个脚本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模式(+(...)
、?(...)
、+(...)
等(需要设置extglob
shell选项。在脚本开头添加shopt -s extglob
。