标签:
脚本 sh05.sh
#!/bin/bash # Program # Program shows the effect of shift function # History: # 2015/9/6 zengdp First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH echo "Total parameter number is ==> $#" echo "You whole parameter is ==> ‘$@‘" shift echo "Total parameter number is ==> $#" echo "You whole parameter is ==> ‘$@‘" shift 3 echo "Total parameter number is ==> $#" echo "You whole parameter is ==> ‘$@‘"
运行 sh sh05.sh one two three four five six
得到
Total parameter number is ==> 6 You whole parameter is ==> ‘one two three four five six‘ Total parameter number is ==> 5 You whole parameter is ==> ‘two three four five six‘ Total parameter number is ==> 2 You whole parameter is ==> ‘five six‘
光看结果你就可以知道啦,那个 shift 会移动变量,而且 shift 后面可以接数字,代表拿掉最前面的几个参数的意思。 上面的运行结果中,第一次进行 shift 后他的显示情况是『 one two three four five six』,所以就剩下五个啦!第二次直接拿掉三个,就变成『 two three four five six 』啦! 这样这个案例可以了解了吗?理解了 shift 的功能了吗?
标签:
原文地址:http://www.cnblogs.com/jacson/p/4786554.html