linux 中 shift命令

发布时间 2023-11-05 17:02:03作者: 小鲨鱼2018

 

linux 中shift命令应用与函数内部,调用一次,表示参数左移一位;$#表示shell参数的个数,调用shift一次, $#减少1.

分别处理每个参数,移出去的参数不再可用;

举例:

001、

[root@pc1 test2]# ls
a.sh
[root@pc1 test2]# cat a.sh                ## 测试脚本
#!/bin/bash

echo "parameters: $*"                     ## $*是shell脚本内置变量,输出所有的参数
echo "num: $#"                            ## $#是shell内置变量,表示参数的个数
shift                                     ## 次数执行一次shift,参数左移一位
echo "shift one time: parameters: $*"     ## 输出所有参数
echo "shift one time: num: $#"            ## 输出此时的参数个数
[root@pc1 test2]# bash a.sh               ## 执行脚本
parameters:
num: 0
shift one time: parameters:
shift one time: num: 0

 

 

 

 

 

 

 

 

 

参考:

01、https://blog.csdn.net/dai9812/article/details/128702875