先看下面的一段代码:
#!/bin/bash
#the name is "test"
echo $@
echo $*
echo "$@"
echo "$*"
a1=($@)
b1=($*)
a2=("$@")
b2=("$*")
echo 'the number of parameters in $@ is '${#a1[*]}
echo 'the number of parameters in $* is '${#b1[*]}
echo 'the number of parameters in "$@" is '${#a2[*]}
echo 'the number of parameters in "$*" is '${#b2[*]}
exit 0
在终端中运行 sh test p1 p2 "p3 p4"
输出结果为:
p1 p2 p3 p4
p1 p2 p3 p4
p1 p2 p3 p4
p1 p2 p3 p4
the number of parameters in $@ is 4
the number of parameters in $* is 4
the number of parameters in "$@" is 3
the number of parameters in "$*" is 1
从上面的结果可以看出,$@,$*区别不是很大,最主要的区别是"$@","$*"。在"$@"中参数为分解为p1 p2 "p3 p4";在"$*"中参数则是一个整体"p1 p2 p3 p4"。(个人理解!)
阅读(1081) | 评论(0) | 转发(0) |