加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – $@和“$@”之间有什么区别吗?

发布时间:2020-12-16 01:10:04 所属栏目:安全 来源:网络整理
导读:参见英文答案 Accessing bash command line args $@ vs $*4个 $@和“$@”之间有什么区别吗? 我知道非特殊字符可能存在差异,但带有输入参数的@符号呢? 是! $cat a.shecho "$@"echo $@ 我们来运行吧: $./a.sh 2 "3 4" 52 3 4 5 # output for "$@"2 3 4 5 #
参见英文答案 > Accessing bash command line args $@ vs $*4个
$@和“$@”之间有什么区别吗?

我知道非特殊字符可能存在差异,但带有输入参数的@符号呢?

是!
$cat a.sh
echo "$@"
echo $@

我们来运行吧:

$./a.sh 2 "3     4" 5
2 3     4 5                  # output for "$@"
2 3 4 5                      # output for $@  -> spaces are lost!

正如您所看到的,使用$@会使参数在用作参数时“丢失”某些内容.有关详细说明,请参见-for-example- I just assigned a variable,but echo $variable shows something else.

从GNU Bash manual –> 3.4.2 Special Parameters开始:

@

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读