转自:http://www.chengyongxu.com/blog/bash-shell%E4%B8%ADshift%E7%94%A8%E6%B3%95/
shift可以用来向左移动位置参数。
Shell的名字 $0
第一个参数 $1
第二个参数 $2
第n个参数 $n
所有参数 $@ 或 $*
参数个数 $#
shift默认是shift 1
以下边为例:
01 |
cat shift .sh |
02 |
#----------------------------输出文字-开始---------------------------- |
03 |
#!/bin/bash |
04 |
until [
-z "$1" ] #
Until all parameters used up |
05 |
do |
06 |
echo "$@
" |
07 |
shift |
08 |
done |
09 |
#----------------------------输出文字-结束---------------------------- |
10 |
11 |
sh shift .sh
1 2 3 4 5 6 7 8 9 |
12 |
#----------------------------输出文字-开始---------------------------- |
13 |
1
2 3 4 5 6 7 8 9 |
14 |
2
3 4 5 6 7 8 9 |
15 |
3
4 5 6 7 8 9 |
16 |
4
5 6 7 8 9 |
17 |
5
6 7 8 9 |
18 |
6
7 8 9 |
19 |
7
8 9 |
20 |
8
9 |
21 |
9 |
22 |
#----------------------------输出文字-结束---------------------------- |