shell常用基本命令之七 shift

来源:互联网 发布:java重载函数 参数子类 编辑:程序博客网 时间:2024/06/01 12:14

1.shift的功能

1.所有的位置参数都左移1位,即$2变$1,$3变$2

2.$# 减1

2.举例

[root@nn shell]# cat shift_fun.sh#!/bin/bash echo "number of arguments is $#"echo "What you input is:"while [[ "$*" != "" ]]do echo "$1"shiftdone[root@nn shell]# ./shift_fun.sh hello worldnumber of arguments is 2What you input is:helloworld[root@nn shell]# 
shift就是起到移位的作用
#!/bin/bash while [ "$#" -gt 0 ]do echo $*shiftdone运行结果:[root@nn shell]# ./shift_fun1.sh 9 8 7 6 5 4 3 2 19 8 7 6 5 4 3 2 18 7 6 5 4 3 2 17 6 5 4 3 2 16 5 4 3 2 15 4 3 2 14 3 2 13 2 12 11


0 0
原创粉丝点击