bash手册(我在OSX上使用4.3.42版本)指出,垂直条形的‘\’字符被用作文件全局中多个文件模式的分隔符。因此,以下内容应适用于我的系统:
projectFiles=./config/**/*|./support/**/*但是,第二种模式在该目录结构中的最后一个文件上提供了一个“拒绝权限”,因此该模式永远不会被解析为projectFiles。我试过了这方面的变化,包括在括号中包装模式,
projectFiles=(./config/**/*)|(./support/**/*)这是在手册中列出的,但也不起作用。
对我做错了什么有什么建议吗?
发布于 2016-05-28 17:46:23
你可能指的是man bash中的这个部分
If the extglob shell option is enabled using the shopt 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 fol- lowing 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
正如所解释的那样,|分隔符在模式列表中工作,但只在启用extglob时:
shopt -s extglob试试这个:
projectFiles=*(./config/**/*|./support/**/*)正如@BroSlow在评论中指出的:
请注意,您可以在不使用
extglob,./{config,support}/**/*的情况下这样做,后者只需扩展到带有配置的路径和带有支持空间分隔的路径,然后进行模式匹配。或者./@(config|support)/**/*和extglob。这两种看起来都更干净。
@chepner的评论也值得一提:
而且,在简单的赋值过程中根本不执行全局操作;尝试
foo=*,然后将echo "$foo"与echo $foo进行比较。在数组赋值过程中确实会出现全局现象;请参阅foo=(*); echo "${foo[@]}"
https://stackoverflow.com/questions/37501965
复制相似问题