shift n
$*中的参数向左移动n个。
myprog
#!/bin/sh
echo There are $# args
echo They are $*
echo Now, I\'ll use the SHIFT command
shift 2
echo it is $*, and total $#
运行./myprog a b c d e f
There are 6 args
They are a b c d e f
Now, I'll use the SHIFT command
it is c d e f, and total 4
shift命令会重新分配命令行参数对应位置参数,在shift n后,所有的$*中的参数都会向左移动n个位置,同时$#也会减少n,shift命令不会影响到参数0的位置。一旦移动成功,被移动的参数将会丢失,所以一定要注意保存。