【问题标题】:Including path portions in xtended pattern matching operators在扩展模式匹配运算符中包含路径部分
【发布时间】:2020-04-22 19:55:00
【问题描述】:

给定以下目录结构,其中所有叶子都是文件,

a
├── b
│   ├── d
│   │   └── f
│   └── e
│       └── g
└── c
    ├── d
    │   └── h
    └── e
        └── i

以下命令列出文件fh

$ ls a/@(b|c)/d/.

但以下未能列出 fi

$ ls a/@(b/d|c/e)
ls: cannot access 'a/@(b/d|c/e)': No such file or directory

显然,我不能在 pattern-list 中添加斜线。我的问题是一个,但也许把它分成几块更好:

  • 为什么?
  • 是否有任何内在原因导致无法做到这一点?
  • 如何使用 oneliner 获得相同的效果?

【问题讨论】:

  • 扩展 glob 的模式不能使用 /,因此您会收到该错误。

标签: bash path pattern-matching glob


【解决方案1】:

我的直觉告诉我 Filename Expansion 可以生成 filenames 但不能生成 pathnames。

在这种情况下,您可以使用Brace Expansion

ls a/{b/d,c/e}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-15
    • 1970-01-01
    • 2018-07-09
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多