所谓位置参数(positional parameter)就是指Shell脚本的命令行参数,参数有很多,先介绍其中二个,如下:
$*
$@
"$*"
"$@"
先编写一脚本,内容如下:
执行结果如下:
<<<<<<<<<<<<<<<1>>>>>>>>>>>>>>
i is hello
i is the
i is world
i is oops
<<<<<<<<<<<<<<<2>>>>>>>>>>>>>>
i is hello
i is the
i is world
i is oops
<<<<<<<<<<<<<<<3>>>>>>>>>>>>>>
i is hello the world oops
<<<<<<<<<<<<<<<4>>>>>>>>>>>>>>
i is hello
i is the world
i is oops
由执行结果可以得知,在没有双引号的情况下,$*和$@的结果是一样的,并且不会保留空白(即引号里面的the world变成两个变量);而"$*"则是将所有参数视为单个字符串,即”$1 $2 $3 …”,最后"$@"刚是将所有参数视为个体,并保留在每个参数里的空白,因此也就保留了真正的参数值。