码迷,mamicode.com
首页 > 其他好文 > 详细

$*和$@之间差别代码分析

时间:2016-01-01 09:23:02      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/bash
set ‘apple pie‘ pears peaches
for i in $*           /*单引號被去掉,循环单个字符输出*/
do echo $i

done

[root@luozhonghua Ex_14.02-14.31]# sh 14-14-1
apple
pie
pears
peaches

--------------------------------------------------------------

#!/bin/bash
set ‘apple pie‘ pears peaches
for i in "$*"      /*单引號被去掉。但当作字符串一次输出*/
do echo $i
done

[root@luozhonghua Ex_14.02-14.31]# sh 14-14-2
apple pie pears peaches
[root@luozhonghua Ex_14.02-14.31]#


-----------------------------------------------------------------



#!/bin/bash
set ‘apple pie‘ pears peaches
for i in $@          /*单引號被去掉。循环单个字符输出*/
do echo $i     
done
[root@luozhonghua Ex_14.02-14.31]# sh 14-14-3
apple
pie
pears
peaches


-----------------------------------------------------------------

#!/bin/bash
set ‘apple pie‘ pears peaches
for i in "$@"      /*每一个位置參数都将当成一个加引號的字符串:"apple pie","pears ","peaches"*/
do echo $i
done
[root@luozhonghua Ex_14.02-14.31]# sh 14-14-4
apple pie
pears
peaches









$*和$@之间差别代码分析

标签:

原文地址:http://www.cnblogs.com/gcczhongduan/p/5092993.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!