首页 > 代码库 > shell中 shift的使用

shell中 shift的使用

[root@jboss shell]# cat shift.sh 

#!/bin/bash

until [ $# -eq 0 ];do

   echo "the first is:$1  total is $#"

shift

done

[root@jboss shell]# ./shift.sh  1 2 3 4 5 6 

the first is:1  total is 6

the first is:2  total is 5

the first is:3  total is 4

the first is:4  total is 3

the first is:5  total is 2

the first is:6  total is 1

[root@jboss shell]# cat shiftest.sh 

#!/bin/bash


until [ -z "$1" ]  

do

  echo "$@ "


  shift


done

[root@jboss shell]# ./shiftest.sh 1 2 3 4 5 6 7 8 9 

1 2 3 4 5 6 7 8 9 

2 3 4 5 6 7 8 9 

3 4 5 6 7 8 9 

4 5 6 7 8 9 

5 6 7 8 9 

6 7 8 9 

7 8 9 

8 9 



本文出自 “路由汗水交换成功” 博客,请务必保留此出处http://ghnhl.blog.51cto.com/1630025/1553377

shell中 shift的使用