$*和[email protected]之间差别代码分析

#!/bin/bash

set ‘apple pie‘ pears peaches

for i in $*           /*单引號被去掉,循环单个字符输出*/

do echo $i

done

[[email protected] 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

[[email protected] Ex_14.02-14.31]# sh 14-14-2

apple pie pears peaches

[[email protected] Ex_14.02-14.31]#

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

#!/bin/bash

set ‘apple pie‘ pears peaches

for i in [email protected]          /*单引號被去掉。循环单个字符输出*/

do echo $i

done

[[email protected] Ex_14.02-14.31]# sh 14-14-3

apple

pie

pears

peaches

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

#!/bin/bash

set ‘apple pie‘ pears peaches

for i in "[email protected]"      /*每一个位置參数都将当成一个加引號的字符串:"apple pie","pears ","peaches"*/

do echo $i

done

[[email protected] Ex_14.02-14.31]# sh 14-14-4

apple pie

pears

peaches

时间: 2024-12-23 02:08:57