shell 特殊變量詳解

$0 獲取當前執行腳本的名稱,包括路徑

[root@centos test]# cat test.sh
echo $0 

[root@VM_102_244_centos test]# bash test.sh
test.sh

#包括路徑
[root@VM_102_244_centos ~]# bash ~/test/test.sh 
/root/test/test.sh

$n 獲取當前執行的shell腳本的第N個參數,n=1..9,當n爲0時表示腳本的文件名,若是n大於9,用大括號括起來 ${10}

[root@VM_102_244_centos test]# cat test.sh
echo $1 $3 ${10} 

[root@VM_102_244_centos test]# bash test.sh a b c d e f g h e i g k
a c i
$#:傳遞到腳本的參數數量;
$*和$@:傳遞到腳本的全部參數;
$?:推出狀態;0表示無錯誤;1表示有錯誤;
$$:腳本運行的進程號,即當前shell的進程號;
相關文章
相關標籤/搜索