有很多特殊变量是被Shell自动赋值的,我们已经遇到了$?
和$1
,现在总结一下:
位置参数可以用shift
命令左移。比如shift 3
表示原来的$4
现在变成$1
,原来的$5
现在变成$2
等等,原来的$1
、$2
、$3
丢弃,$0
不移动。不带参数的shift
命令相当于shift 1
。例如:
#! /bin/sh echo "The program $0 is now running" echo "The first parameter is $1" echo "The second parameter is $2" echo "The parameter list is $@" shift echo "The first parameter is $1" echo "The second parameter is $2" echo "The parameter list is $@"