Why do I get this error using {1..9} in zsh?

Léo Léopold Hertz 준영 picture Léo Léopold Hertz 준영 · Apr 30, 2009 · Viewed 13.8k times · Source

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

Answer

chaos picture chaos · Apr 30, 2009

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.