#Bash 的 shift 命令
shift [N]
功能
移动参数列表。
将参数列表
$@向前移动N个参数,即清除前N个参数。
类型
Bash 内置命令。
参数
N- 移动参数个数;默认为 1
#示例
#!/usr/bin/bash
echo $@ # 查看参数列表
shift # 移除第一个参数
echo $@ # 查看参数列表
shift 2 # 移除前两个参数
echo $@ # 查看参数列表
运行结果:
$ ./demo.sh 1 2 3 4 5
1 2 3 4 5
2 3 4 5
4 5
#推荐阅读
#手册
shift: shift [n]
Shift positional parameters.
Rename the positional parameters $N+1,$N+2 ... to $1,$2 ... If N is
not given, it is assumed to be 1.
Exit Status:
Returns success unless N is negative or greater than $#.