1. 程式人生 > >淺談linux中shell變數$#,[email protected],$0,$1,$2,$?的含義解釋

淺談linux中shell變數$#,[email protected],$0,$1,$2,$?的含義解釋

淺談linux中shell變數$#,[email protected],$0,$1,$2,$?的含義解釋

下面小編就為大家帶來一篇淺談linux中shell變數$#,[email protected],$0,$1,$2的含義解釋。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧  

摘抄自:ABS_GUIDE

下載地址:http://www.tldp.org/LDP/abs/abs-guide.pdf

linux中shell變數$#,[email protected],$0,$1,$2的含義解釋:

變數說明: 

$$ 
Shell本身的PID(ProcessID) 
$! 
Shell最後執行的後臺Process的PID 
$? 
最後執行的命令的結束程式碼(返回值) 
$- 
使用Set命令設定的Flag一覽 
$* 
所有引數列表。如"$*"用「"」括起來的情況、以"$1 $2 … $n"的形式輸出所有引數。 
[email protected] 
所有引數列表。如"[email protected]"用「"」括起來的情況、以"$1" "$2" … "$n" 的形式輸出所有引數。 
$# 
新增到Shell的引數個數 
$0 
Shell本身的檔名 
$1~$n

新增到Shell的各引數值。$1是第1引數、$2是第2引數…。

示例:

1 #!/bin/bash
 2 #
 3 printf "The complete list is %s\n" "$$"
 4 printf "The complete list is %s\n" "$!"
 5 printf "The complete list is %s\n" "$?"
 6 printf "The complete list is %s\n" "$*"
 7 printf "The complete list is %s\n" "[email protected]

"
 8 printf "The complete list is %s\n" "$#"
 9 printf "The complete list is %s\n" "$0"
10 printf "The complete list is %s\n" "$1"
11 printf "The complete list is %s\n" "$2

結果:

[[email protected] ~]$ bash params.sh 123456 QQ
The complete list is 24249
The complete list is
The complete list is 0
The complete list is 123456 QQ
The complete list is 123456
The complete list is QQ
The complete list is 2
The complete list is params.sh
The complete list is 123456
The complete list is QQ
Have a nice day!!!

以上這篇淺談linux中shell變數$#,[email protected],$0,$1,$2的含義解釋就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援指令碼之家。

您可能感興趣的文章: