无法使系统变量适用于手册

时间:2022-02-27 10:39:42

I have the following system variable in .zshrc

我在.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?

如何在Zsh中使用系统变量运行上述命令?

2 个解决方案

#1


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.

根据我的调查,看起来zsh在$ substitution之前执行<>替换。这意味着当你使用$ variant时,它首先尝试<>替换(没有任何东西)然后$ substitution(有效),你留下包含<>字符的字符串。

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:

当你不使用$ manuals时,它首先尝试<>替换它的工作原理。这是一个有序的问题。下面的最终版本显示了如何推迟扩展,以便它们同时发生:

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

#2


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.

使用变量时,'〜'告诉zsh执行<0-9>的扩展。 zsh参考卡告诉您如何执行此操作以及更多操作。

#1


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.

根据我的调查,看起来zsh在$ substitution之前执行<>替换。这意味着当你使用$ variant时,它首先尝试<>替换(没有任何东西)然后$ substitution(有效),你留下包含<>字符的字符串。

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:

当你不使用$ manuals时,它首先尝试<>替换它的工作原理。这是一个有序的问题。下面的最终版本显示了如何推迟扩展,以便它们同时发生:

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

#2


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.

使用变量时,'〜'告诉zsh执行<0-9>的扩展。 zsh参考卡告诉您如何执行此操作以及更多操作。