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

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

时间:2014-08-09 23:22:59      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:shell   linux   

#!/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









$*和$@之间区别代码分析,布布扣,bubuko.com

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

标签:shell   linux   

原文地址:http://blog.csdn.net/luozhonghua2014/article/details/38460495

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