shift:造成参数变量号码偏移
-
[root@RHEL6 scripts]# more sh08.sh
-
#!/bin/bash
-
#program:
-
#program shows the script name,parameters...
-
#History
-
#2015//06/17 Awake First release
-
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
-
export PATH
-
-
echo "Total parameter number is $#"
-
echo "Your whole parameter is $@"
-
shift //进行第一次“一个变量的shift”
-
-
echo "Total parameter number is $#"
-
echo "Your whole parameter is $@"
-
shift 3 //进行第二次“三个变量的shift”
-
-
echo "Total parameter number is $#"
-
echo "Your whole parameter is $@"
-
[root@RHEL6 scripts]# ./sh08.sh one two three four five six //给予六个参数
-
Total parameter number is 6 //最原始的的参数变量情况
-
Your whole parameter is one two three four five six
-
Total parameter number is 5 //第一次偏移,看下面发现第一个one不见了
-
Your whole parameter is two three four five six
-
Total parameter number is 2 //第二次偏移掉3个,那么也就是“two three four”不见了
-
Your whole parameter is five six
-
[root@RHEL6 scripts]#
光看结果你就可以知道,shift会移动变量,而且shift后面可以接数字,代表拿掉最前面的几个参数的意思。
阅读(1109) | 评论(0) | 转发(0) |