代码之家  ›  专栏  ›  技术社区  ›  minseong

glob模式不会在zsh中的文件内部展开

  •  0
  • minseong  · 技术社区  · 6 年前

    这在命令行中起作用:

    $ export exclude=BigDir
    $ for d in ^$exclude/ ; do echo "$d" ; done
    SmallDir/
    SmallerDir/
    $
    

    但在文件中,它根本不起作用

    #!/bin/zsh
    
    exclude=BigDir
    for d in ^$exclude/ ; do echo "$d" ; done
    

    跑步 ./test 或者不管我是如何保存它的 字面意义的

    ^BigDir/
    

    如何使其在脚本文件中正确展开?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Inian    6 年前

    ? 由shell和正则表达式构造使用 ^ , $ . 这个 for 进行正则表达式匹配以排除提供的目录,因为它只进行路径名扩展(aka)。全球扩展)

    除非你让我知道要治疗的贝壳 ^ $ 通过启用扩展全局选项,将其视为特殊 extglob 在里面 bash extendedglob 在里面 zsh

    所以你可能只需要

    setopt extendedglob
    print -rl ^BigDir*
    

    意义印刷 任何东西 除了与匹配的文件名 BigDir