views:

144

answers:

1

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}?

+2  A: 

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:

zgrep -c compinit /usr/share/man/man[1-9]/zsh*

you'd get the results you expect, because [1-9] is a normal wildcard expression.

chaos
So we have two spaces: one is non-wildcard and the other is wildcard space. If there exists one wildcard, it forces me to use only wildcard characters. In the same way, you can only use non-wildcard characters alone. - - Thank you for your answer!
Masi
@Masi: Not quite. If I had a directory with 1-hello.gif, 2-world.gif, ..., 20-foobar.gif, `{1..20}-*.gif` would work perfectly fine to match them, while `[1-20]-*.gif` would only match the first two. This will cause the same error as in your question if any of the sequentially-numbered files are missing, though.
ephemient
@ephemient: Do you mean that [1-20]File does not work if you do not have, for instance, 7File? -- If so, what is the benefit of using [1-20] instead of {1..20} which does not cause you the problem?
Masi
@Masi: He means that [1-20] does not mean one through twenty; it means the same thing as [120], i.e. any of 1, 2, or 0. The range functionality in [] is only good for the range from one character to another character, like A-Z, a-z, 0-9. It doesn't do ranges like 1-20; for those you have to do other maneuvers.
chaos