040-shell參數$?,$0,$#等

shell腳本中常常會遇到參數shell

 printf "The complete list is %s\n" "$$"vim

shell自己的PID(processID)
 printf "The complete list is %s\n" "$!"bash

Shell 最後運行後臺Process 的PID
 printf "The complete list is %s\n" "$?"code

上一次運行命令的返回值,正常爲0
 printf "The complete list is %s\n" "$*"ip

全部參數
 printf "The complete list is %s\n" "$@"it

全部參數列表。如"$@"用「"」括起來的狀況、以"$1" "$2" … "$n" 的形式輸出全部參數。
 printf "The complete list is %s\n" "$#"後臺

添加shell參數的個數
 printf "The complete list is %s\n" "$0"im

shell自己的文件名
 printf "The complete list is %s\n" "$1""$2"腳本

第一個參數,第二個參數
 文件

[root@cnsz142728 scripts]# vim parameter.sh
  1 #!/bin/bash
  2  printf "The complete list is %s\n" "$$"
  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" "$0"
  9  printf "The complete list is %s\n" "$1"
 10  printf "The complete list is %s\n" "$2"

"parameter.sh" 10L, 381C written                                                                                                                                                                                          
[root@cnsz142728 scripts]# ./parameter.sh 123 45
The complete list is 30763
The complete list is 
The complete list is 0
The complete list is 123 45
The complete list is 123
The complete list is 45
The complete list is 2
The complete list is ./parameter.sh
The complete list is 123
The complete list is 45

對照着來,就明白各個參數的含義。

相關文章
相關標籤/搜索