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

数组 – Bash中的`$*`和`$@`有什么区别

发布时间:2020-12-16 01:28:20 所属栏目:安全 来源:网络整理
导读:参见英文答案 What’s the difference between $@ and $* in UNIX?4个 当我想要bash函数的所有参数时,我总是使用$@但最近我发现$*也以相同的方式工作,它也可以用作数组索引. 我的问题是Bash中$*和$@之间的区别是什么?我应该选择哪一个? Bash manual在这个
参见英文答案 > What’s the difference between $@ and $* in UNIX?4个
当我想要bash函数的所有参数时,我总是使用$@但最近我发现$*也以相同的方式工作,它也可以用作数组索引.

我的问题是Bash中$*和$@之间的区别是什么?我应该选择哪一个?

Bash manual在这个主题上非常明确:
  • $*

    All of the positional parameters,seen as a single word.

    Note: $* must be quoted.

  • $@

    Same as $*,but each parameter is a quoted string,that is,the parameters are passed on intact,without interpretation or expansion. This means,among other things,that each parameter in the argument list is seen as a separate word.

    Note: Of course,$@ should be quoted.

(编辑:李大同)

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

    推荐文章
      热点阅读