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

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

问题描述

我估计句柄 $ @ 在shell脚本是给脚本中的所有参数数组。这是真的?

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

我问,因为我通常使用搜索引擎收集信息,但我不能谷歌的 $ @ 和我已经长大太习惯很容易地得到服务的一切。

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

推荐答案

是的。请参阅的bash下特殊参数

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

特殊参数

外壳特意把几个参数。这些参数可能仅被引用;对它们赋值是不允许的。

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为空,参数结合而不分隔器。

* 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天全站免登陆