$ @和"$ @"之间有什么区别吗? [英] Is there any difference between $@ and "$@"?

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

问题描述

$ @ "$ @" 之间是否有区别?

我知道非特殊字符可能有所不同,但是带有输入参数的 @ 符号又如何呢?

I understand there may be differences for non special characters, but what about the @ sign with input arguments?

推荐答案

是!

$ 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!

如您所见,使用 $ @ 可使参数在用作参数时丢失"某些内容.参见-例如-我刚刚分配了一个变量,但是echo $ variable显示了其他内容,以对此进行详细说明.

As you can see, using $@ makes the parameters to "lose" some content when used as a parameter. See -for example- I just assigned a variable, but echo $variable shows something else for a detailed explanation of this.

来自 GNU Bash手册-> 3.4.2特殊参数:

@

($ @)从一个开始扩展到位置参数.何时扩展出现在双引号内,每个参数扩展为一个单独的单词.也就是说,"$ @"等效于"$ 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).

这篇关于$ @和"$ @"之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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