为什么在 zsh 中使用 {1..9} 会出现此错误?
我运行以下代码,
zgrep -c compinit /usr/share/man/man{1..9}/zsh*
我得到
zsh: no matches found: /usr/share/man/man2/zsh*
这很奇怪,因为以下工作
echo Masi{1..9}/masi
这表明问题可能是 Zsh 中的错误。
上述内容是 {1..9} 的 Zsh 中的错误吗?
I run the following code
zgrep -c compinit /usr/share/man/man{1..9}/zsh*
I get
zsh: no matches found: /usr/share/man/man2/zsh*
This is strange, since the following works
echo Masi{1..9}/masi
This suggests me that the problem may be a bug in Zsh.
Is the above a bug in Zsh for {1..9}?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 zsh 中,如果您想在文件名中使用范围,zle 会在其可以扩展的任何真实名称上提供
<1-n>
。 也就是说:然后在最后的
b
后立即点击
,您将看到print a0b a1b a5b a7b
在线。对于所有其他意图和目的 - 也许是全方位的要求、非文件和脚本使用 - 我会使用相当简洁的惯用 zsh 循环来表达这一点:
将允许您处理数字 1 到 50 的整个序列范围:) 之后你可以做各种有用的事情,例如尚不存在的文件集合:
In zsh, if you want to use ranges in filenames, zle offers
<1-n>
on any real names it can expand on. That is to say:And then hit
<Tab>
right after the finalb
would leave you withprint a0b a1b a5b a7b
expanded on the line.For all other intents and purposes - perhaps full range requirements, non-file and scripting use - I'd express this using the rather succinct idiomatic zsh loop as:
Will allow you process the whole sequence range of numbers 1 to 50 :) after which you can do all sorts of useful things with, such as a file collection that doesn't exist yet:
这不是一个错误,而且它在文字中工作得很好。 您在这里遇到的麻烦是
{1..9}
不是像*
那样的通配符表达式; 正如您的 echo 示例所示,这是一个迭代扩展。 因此,您的 zgrep 示例与您在命令行中输入每个备用版本完全相同,然后由于 man2 中没有以 zsh 开头的手册页,因此会出错。 (它因未能找到匹配而出错,而不是与大括号序列扩展本质上相关的任何内容。)另一方面,如果您这样做:
您会得到您期望的结果,因为
[1-9 ]
是一个普通的通配符表达式。It's not a bug, and it is working inside words fine. The trouble you're having here is that
{1..9}
is not a wildcard expression like*
is; as your echo example shows, it's an iterative expansion. So your zgrep example is exactly the same as if you had typed each alternate version into the command line, and then since there are no man pages starting with zsh in man2, it errors out. (It's erroring out on a failure to find a match, not anything intrinsically related to your brace sequence expansion.)If you did this, on the other hand:
you'd get the results you expect, because
[1-9]
is a normal wildcard expression.