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

shell脚本中的$@和$*之间有什么区别?

发布时间:2020-12-15 20:05:44 所属栏目:安全 来源:网络整理
导读:在shell脚本中,$ @和$ *之间有什么区别? 哪一个是获得脚本参数的首选方式? 不同的shell解释器之间有不同吗? 从 here: $@ behaves like $* except that when quoted the arguments are broken up properly if there are spaces in them. 以这个脚本为例(
在shell脚本中,$ @和$ *之间有什么区别?

哪一个是获得脚本参数的首选方式?

不同的shell解释器之间有不同吗?

从 here:

$@ behaves like $* except that when quoted the arguments are broken up properly if there are spaces in them.

以这个脚本为例(取自链接的答案):

for var in "$@"
do
    echo "$var"
done

给出:

$ sh test.sh 1 2 '3 4'
1
2
3 4

现在将“$ @”更改为$ *:

for var in $*
do
    echo "$var"
done

你得到这个:

$ sh test.sh 1 2 '3 4'
1
2
3
4

(使用Google找到答案)

(编辑:李大同)

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

    推荐文章
      热点阅读