区别:$@ $*相同点:都是引用所有参数
不同点:只有在双引号中体现出来。假设在脚本运行时写了三个参数(分别存储在$1 $2 $3)则"$*" 等价于 “$1 $2 $3"(传递了一个参数);而“$@" 等价于 "$1" "$2" "$3"(传递了三个参数)
例子一
##dels.shecho "number:$#"echo "scname:$0"echo "first :$1"echo "second:$2"echo "argume:$@"echo "show parm list:$*"echo "show process id:$$"echo "show precomm stat: $?"
执行结果
例子2:
#!/bin/sh
num=$#
name=$0
echo "number:$num"
echo "scname:$name"
echo $0
echo $1
echo $2
for ((i=0; i
do
echo "$i"
done
echo "argume:$@"
for key in $@
do
echo $key
done
echo "-----------------"
for key in "$@"
do
echo $key
done
echo "-----------------------------"
for key2 in $*
do
echo $key2
done
echo "-----------------"
for key2 in "$*"
do
echo $key2
done
echo "show process id:$$"
cho
echo "show precomm stat: $?"
执行结果