標籤:
指令碼 sh05.sh
#!/bin/bash# Program# Program shows the effect of shift function# History:# 2015/9/6 zengdp First releasePATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHecho "Total parameter number is ==> $#"echo "You whole parameter is ==> ‘[email protected]‘"shiftecho "Total parameter number is ==> $#"echo "You whole parameter is ==> ‘[email protected]‘"shift 3echo "Total parameter number is ==> $#"echo "You whole parameter is ==> ‘[email protected]‘"
運行 sh sh05.sh one two three four five six
得到
Total parameter number is ==> 6You whole parameter is ==> ‘one two three four five six‘Total parameter number is ==> 5You whole parameter is ==> ‘two three four five six‘Total parameter number is ==> 2You whole parameter is ==> ‘five six‘
光看結果你就可以知道啦,那個 shift 會移動變數,而且 shift 後面可以接數字,代表拿掉最前面的幾個參數的意思。 上面的運行結果中,第一次進行 shift 後他的顯示情況是『 one two three four five six』,所以就剩下五個啦!第二次直接拿掉三個,就變成『 two three four five six 』啦! 這樣這個案例可以瞭解了嗎?理解了 shift 的功能了嗎?
shift移動變數