Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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:

$ touch a0b a1b a5b a7b
$ print a<0-100>b

And then hit <Tab> right after the final b would leave you with print 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:

for n ({1..50}); do print $n; done

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:

arr=($(for n ({1..50}); do print /my/path/file$n.txt; done)) && print $arr[33]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top