我认为shell脚本中的句柄$@是给定脚本的所有参数的数组。这是真的吗?
我问这个问题是因为我通常使用搜索引擎来收集信息,但我不能为$@而谷歌,而且我已经太习惯于轻松地获得所有服务。
我认为shell脚本中的句柄$@是给定脚本的所有参数的数组。这是真的吗?
我问这个问题是因为我通常使用搜索引擎来收集信息,但我不能为$@而谷歌,而且我已经太习惯于轻松地获得所有服务。
是的。请在特殊参数下查看Bash的手册页(你要去的第一件事):
Special Parameters The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed. * Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators. @ 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).
仅仅从阅读中,我永远不会理解“$@”展开为一个单独的参数列表。然而,“$*”是一个由所有参数加在一起组成的参数。
如果还是没有意义,就这么做。
Bash特殊参数通过四个示例shell脚本进行解释