在shell脚本中,美元符号后面跟着一个at符号(@)是什么意思?
例如:
umbrella_corp_options $@
在shell脚本中,美元符号后面跟着一个at符号(@)是什么意思?
例如:
umbrella_corp_options $@
当前回答
$@基本上用于引用shell-script的所有命令行参数。 $1, $2, $3是第一个命令行参数,第二个命令行参数,第三个参数。
其他回答
$@是传递给脚本的所有参数。
例如,如果你调用。/ somcript .sh foo bar,那么$@将等于foo bar。
如果你有:
./someScript.sh foo bar
然后在somscript .sh引用中:
umbrella_corp_options "$@"
这将被传递给伞状的corp_options,每个单独的参数都用双引号括起来,允许从调用者那里获取带有空格的参数并将它们传递出去。
它们通常用于简单地将所有参数传递给另一个程序
[root@node1 shell]# ./my-script hi 11 33 嗨11 33 [root@node1
摘自手册:
@ 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).
以下是命令行参数:
$@ =将所有参数存储在string列表中 $* =将所有参数存储为单个字符串 $# =存储参数的数量
$@基本上用于引用shell-script的所有命令行参数。 $1, $2, $3是第一个命令行参数,第二个命令行参数,第三个参数。