linux中shell变量$#,$@,$0,$1,$2的含义解释(转)
生活随笔
收集整理的這篇文章主要介紹了
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的含义解释(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax上传plupload的使用
- 下一篇: Xftp连接linux(ubuntu)时