关注此 question 中提到的 @()
语法:
[[ $OSTYPE == *@(darwin|freebsd|solaris|cygwin|openbsd)* ]]
这个语法从何而来?为什么在这种情况下使用它?和 有什么区别:
[[ $OSTYPE =~ (darwin|freebsd|solaris|cygwin|openbsd) ]]
或
[[ $OSTYPE == *(darwin|freebsd|solaris|cygwin|openbsd) ]]
这一切似乎都是等价的。
是否使用此语法代替 =~
运算符以提高正则表达式的可移植性?
谢谢你的解释
最佳答案
在 man bash
中搜索 extglob
选项:
If the
extglob
shell option is enabled using theshopt
builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a|
. Composite patterns may be formed using one or more of the following sub-patterns:?(pattern-list) Matches zero or one occurrence of the given patterns *(pattern-list) Matches zero or more occurrences of the given patterns +(pattern-list) Matches one or more occurrences of the given patterns @(pattern-list) Matches one of the given patterns !(pattern-list) Matches anything except one of the given patterns
关于regex - bash 中的@(...|...|...) 语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35812293/