views:

38

answers:

2

I have the following system variable in .zshrc

manuals='/usr/share/man/man<1-9>'

I run unsuccessfully

zgrep -c compinit $manuals/zsh*

I get

zsh: no matches found: /usr/share/man/man<1-9>/zsh*

The command should be the same as the following command which works

zgrep -c compinit /usr/share/man/man<1-9>/zsh*

How can you run the above command with a system variable in Zsh?

A: 

From my investigations, it looks like zsh performs <> substitution before $ substitution. That means when you use the $ variant, it first tries <> substitution (nothing there) then $ substitution (which works), and you're left with the string containing the <> characters.

When you don't use $manuals, it first tries <> substitution and it works. It's a matter of order. The final version below shows how to defer expansion so they happen at the same time:

These can be seen here:

> manuals='/usr/share/man/man<1-9>'

> echo $manuals
  /usr/share/man/man<1-9>

> echo /usr/share/man/man<1-9>
  /usr/share/man/man1 /usr/share/man/man2 /usr/share/man/man3
  /usr/share/man/man4 /usr/share/man/man5 /usr/share/man/man6
  /usr/share/man/man7 /usr/share/man/man8

> echo $~manuals
  /usr/share/man/man1 /usr/share/man/man2 /usr/share/man/man3
  /usr/share/man/man4 /usr/share/man/man5 /usr/share/man/man6
  /usr/share/man/man7 /usr/share/man/man8
paxdiablo
I this time accept Pax's answer because of great examples. Thank you for your answer!
Masi
+1  A: 

Try:

$> manuals=/usr/share/man/man<0-9>
$> zgrep -c compinit ${~manuals}/zsh*

The '~' tells zsh to perform expansion of the <0-9> when using the variable. The zsh reference card tells you how to do this and more.

sykora
@sykora: Do you know how you can put these folders to be run for run-help, such that I can search the help files by just typing $ compinit Esc-h?
Masi