Bash 中的 $@ 是什么? [英] What is $@ in Bash?

查看:35
本文介绍了Bash 中的 $@ 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为 shell 脚本中的句柄 $@ 是提供给脚本的所有参数的数组.这是真的吗?

I reckon that the handle $@ in a shell script is an array of all arguments given to the script. Is this true?

我之所以这么问是因为我通常使用搜索引擎来收集信息,但我无法在 Google 上搜索 $@,而且我已经习惯于轻松获得所有内容.

I ask because I normally use search engines to gather information, but I can't google for $@ and I have grown too accustomed to easily getting served everything.

推荐答案

是的.请参阅 Bash 手册页(第一件事你去)下特殊参数:

Yes. Please see the man page of Bash (the first thing you go to) under Special Parameters:

特殊参数

shell 对几个参数进行了特殊处理.这些参数只能被引用;不允许分配给他们.

The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.

* 扩展到位置参数,从 1 开始.当扩展发生在双引号内时,它扩展为单个单词,每个参数的值由 IFS 特殊变量的第一个字符分隔.即"$*"等价于"$1c$2c...",其中c是第一个IFS 变量值的字符.如果未设置 IFS,则参数以空格分隔.如果 IFS 为 null,则连接参数时不插入分隔符.

* 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.

@ 扩展到位置参数,从 1 开始.当扩展发生在双引号内时,每个参数都扩展为一个单独的词.也就是说,"$@" 等价于 "$1" "$2" ...引用扩展发生在一个词内,第一个参数的扩展与原词的开头部分连接,最后一个参数的扩展与原词的最后部分连接.当没有位置参数时,"$@"$@ 扩展为空(即,它们被删除).

@ 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 中的 $@ 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆