$^@(美元插入符)在 shell 脚本中是什么意思?

man*_*uck 0 shell zsh shell-script

我找到了参数扩展的参考资料,但没有一个解释其作用$^@。从上下文来看,我认为它用于扩展 例如~/$^@into ~/$1 ~/$2 ...,但我不确定,而且我找不到任何确认。除了解释之外,我很高兴知道这个扩展的名称,以及有关它的文档的链接(如果可能)。谢谢!

编辑:我被告知这可能是 zsh 特有的。如果有人有更多信息,请告诉我。

Kus*_*nda 5

zshshell 中,foo${^array}bar, wherearray是一个数组,如(a b c), 将扩展为fooabar, foobbar, and foocbar(就像大括号扩展一样)而不是字符串fooa, b, 和cbar

$ array=(a b c)
$ print -rC1 foo${^array}bar
fooabar
foobbar
foocbar
$ print -rC1 foo${array}bar
fooa
b
cbar
Run Code Online (Sandbox Code Playgroud)

在您引用的代码中,这用于将~/(用户主目录的路径名)附加到位置参数列表的每个元素:

$ set -- a b c "bumble bee"
$ print -rC1 ~/$^@
/home/myself/a
/home/myself/b
/home/myself/c
/home/myself/bumble bee
Run Code Online (Sandbox Code Playgroud)

~/$^@是相同的~/${^@}$@或者${@}是位置参数列表(通常是给当前脚本或 shell 函数的参数,或者使用set内置实用程序设置的字符串,如上所示)。

zshall在手册中搜索RC_EXPAND_PARAM. 扩展可能最初来自外壳rc