Linux Shell函式

pursuer.chen發表於2016-07-12

介紹

 

 

正文

$?

$?是shell變數,表示"最後一次執行命令"的退出狀態.0為成功,非0為失敗.切記:$?永遠表示shell命令最後一次執行後的退出狀態,當函式執行完畢後,如果又執行了其它命令,則$?不再表示函式執行後的狀態,而表示其它命令的退出狀態

 

$$ 
Shell本身的PID(ProcessID) 
$! 
Shell最後執行的後臺Process的PID 
$? 
最後執行的命令的結束程式碼(返回值) 
$- 
使用Set命令設定的Flag一覽 
$* 
所有引數列表。如"$*":"$1 $2 … $n"的形式輸出所有引數。 
$@ 
所有引數列表。如"$@"以多行的形式"$1" "$2""$n" 輸出所有引數。 
$# 
新增到Shell的引數個數 
$0 
Shell本身的檔名 
$1~$n 
新增到Shell的各引數值。$1是第1引數、$2是第2引數…。 

例:

vim a.sh

 #!/bin/bash
  printf "The complete list is %s\n" "$$"
  printf "The complete list is %s\n" "$!"
  printf "The complete list is %s\n" "$?"
  printf "The complete list is %s\n" "$*"
  printf "The complete list is %s\n" "$@"
  printf "The complete list is %s\n" "$#"
  printf "The complete list is %s\n" "$0"
  printf "The complete list is %s\n" "$1"
  printf "The complete list is %s\n" "$2"

 

 

總結

 

 

 

 

 

備註:

    作者:pursuer.chen

    部落格:http://www.cnblogs.com/chenmh

本站點所有隨筆都是原創,歡迎大家轉載;但轉載時必須註明文章來源,且在文章開頭明顯處給明連結。

《歡迎交流討論》

相關文章