摘抄自:ABS_GUIDE
下載地址:http://www.tldp.org/LDP/abs/abs-guide.pdf
linux中shell變量$#,$@,$0,$1,$2的含義解釋:
變量說明:
$$
Shell本身的PID(ProcessID)
$!
Shell最后運行的后臺Process的PID
$?
最后運行的命令的結束代碼(返回值)
$-
使用Set命令設定的Flag一覽
$*
所有參數列表。如"$*"用「"」括起來的情況、以"$1 $2 … $n"的形式輸出所有參數。
$@
所有參數列表。如"$@"用「"」括起來的情況、以"$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" "$@"
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
結果:
[Aric@localhost ~]$ 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變量$#,$@,$0,$1,$2的含義解釋就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- 區分shell中的 反引號、$()和${}
- 詳解Shell 腳本中 “$” 符號的多種用法
- Shell $0, $#, $*, $@, $?, $$和命令行參數的使用
- 用來檢測輸入的選項$1是否在PATH中的shell腳本
- Shell中的${}、##和%%使用范例
- PowerShell中的特殊變量$null介紹和創建多行注釋小技巧
- PowerShell函數中使用$PSBoundParameters獲取輸入參數列表實例
- PowerShell中的$Input變量使用實例
- PowerShell默認參數$PSDefaultParameterValues結合Out-File輸出到日志文件
- shell腳本中$符號的命令使用匯總