在shell脚本中,美元符号后面跟着一个at符号(@)是什么意思?

例如:

umbrella_corp_options $@

当前回答

$@基本上用于引用shell-script的所有命令行参数。 $1, $2, $3是第一个命令行参数,第二个命令行参数,第三个参数。

其他回答

摘自手册:

@ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" .... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed).

纯$@的使用在大多数情况下意味着“尽可能地伤害程序员”,因为在大多数情况下,它会导致单词分离、空格和参数中的其他字符的问题。

在(猜测的)99%的情况下,需要将它括在"中:"$@"是可以用于可靠地遍历参数的。

for a in "$@"; do something_with "$a"; done

$@是传递给脚本的所有参数。

例如,如果你调用。/ somcript .sh foo bar,那么$@将等于foo bar。

如果你有:

./someScript.sh foo bar

然后在somscript .sh引用中:

umbrella_corp_options "$@"

这将被传递给伞状的corp_options,每个单独的参数都用双引号括起来,允许从调用者那里获取带有空格的参数并将它们传递出去。

$@基本上用于引用shell-script的所有命令行参数。 $1, $2, $3是第一个命令行参数,第二个命令行参数,第三个参数。

它们通常用于简单地将所有参数传递给另一个程序

[root@node1 shell]# ./my-script hi 11 33 嗨11 33 [root@node1