如何在 zsh 中重用星号通配的路径?

SRS*_*333 4 zsh wildcards

我的问题和标题可能不是很好,我提前道歉。

假设我想在以下位置执行一个命令(具体来说,xsdcxxzsh

$ xsdcxx cxx-tree schemas/core/**/*.xsd --output-dir /absolute/path/to/globbed/path
Run Code Online (Sandbox Code Playgroud)

以便生成文件的目录结构与输入.xsd模式位于同一目录中。我该怎么做呢?在 PowerShell 中,这非常简单(假设xsdcxx已经在 中PATH):

> Get-ChildItem -Recurse -Include '*.xsd' | Foreach { xsdcxx cxx-tree --output-dir $_.Directory.Fullname $_.Fullname } 
Run Code Online (Sandbox Code Playgroud)

Sté*_*las 10

使用zsh,那就是:

for f (schemas/core/**/*.xsd) xsdcxx cxx-tree --output-dir $f:h $f
Run Code Online (Sandbox Code Playgroud)

csh 或 vim$f:h$flike的头部(目录名)在哪里。

更改$f$f:P$f:h分别$f:h:P获取文件和文件头的真实路径¹。

在这里,如果没有匹配项,您可能希望更改schemas/core/**/*.xsdschemas/core/**/*.xsd(N)(where Nenabled nullglobfor that one glob extension) 以避免错误。或者(N.)仅限制为常规文件(不包括所有其他类型的文件,如套接字、fifos、目录、符号链接等),或(N-.)还包括常规文件的符号链接。


¹,这是对应文件的规范路径:绝对和无符号链接,就像realpath()标准函数一样。另请参阅作为可能的替代方案的:a:A修饰符info zsh modifiers