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

例如:

umbrella_corp_options $@

当前回答

摘自手册:

@ 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).

其他回答

的意思。

简而言之,$@扩展为从调用者传递给函数或脚本的参数。它的含义与上下文相关:在函数内部,它扩展为传递给该函数的参数。如果在脚本中使用(在函数之外),则扩展为传递给该脚本的参数。

$ cat my-script
#! /bin/sh
echo "$@"

$ ./my-script "Hi!"
Hi!
$ put () { echo "$@"; }
$ put "Hi!"
Hi!

*注意:分词。

shell根据IFS环境变量的内容拆分令牌。默认值为\t\n;即,空格、制表符和换行符。展开“$@”可以得到传入参数的原始副本。扩展$@可能不会。更具体地说,任何包含IFS中出现的字符的参数都可能分裂为两个或多个参数或被截断。

因此,大多数时候你想要使用的是“$@”,而不是$@。

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

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

以下是命令行参数:

$@ =将所有参数存储在string列表中 $* =将所有参数存储为单个字符串 $# =存储参数的数量

摘自手册:

@ 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).

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