阅读948 返回首页    go 阿里云 go 技术社区[云栖]


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

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









最后更新:2017-04-03 05:39:47

  上一篇:go CSS 有趣的边框
  下一篇:go 进程通信、线程同步 概述