免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2289 | 回复: 6
打印 上一主题 下一主题

$@ 和 $*的区别 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-08 10:39 |只看该作者 |倒序浏览
一直没搞清楚 明白的兄弟讲讲 给1分 吼吼

论坛徽章:
0
2 [报告]
发表于 2008-01-08 10:43 |只看该作者
$*   传递给shell script的参数
$@   所有参数,个别的用双引号括起来

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
3 [报告]
发表于 2008-01-08 10:48 |只看该作者
$* 与 $@没有区别
"$*" 与 "$@"才有区别

看看ABS的位置参数
http://www.linuxsir.org/main/doc ... iables2.html#APPREF

论坛徽章:
0
4 [报告]
发表于 2008-01-08 11:04 |只看该作者
TKS  ly

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
5 [报告]
发表于 2008-01-08 12:45 |只看该作者
from bash man:

*
    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.
@
    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).

    *  参数
    扩展为从1开始的位置参数。
    双引号对中的*被扩展为单一的word字,这个字的值是由以第一个IFS字符分隔每个位置参数组成的字符序列。
    即"$*" 扩展为"$1c$2c..", 其中c是IFS值中的第一个字符。
    如果IFS没有定义,那么c为space;如果IFS为空,那么c为空。

    @ 参数
    扩展为从1开始的位置参数。
    双引号对中的@被扩展为多个分开的word字,即"$@" 扩展为"$1" "$2" ...
    如果双引号扩展发生在一个字中,如abc"$@"def,扩展后的第一个字与原始字的开头部分abc相连,扩展后的最后一个字与原始字的后面部分def相连。
    当没有位置参数时,"$@" 和$@扩展为nothing,即它们被移除。

[ 本帖最后由 blackold 于 2008-1-8 13:06 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2008-01-08 14:17 |只看该作者
简单的说,一个是 数组,一个是 字符串

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
7 [报告]
发表于 2008-01-08 19:15 |只看该作者
13 問的第 9 問專門講這個的:
http://bbs.chinaunix.net/viewthr ... p;page=7#pid1628522
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP