$?
範例
執行
$ true
接著執行
$ echo $?
顯示
0
執行
$ false
接著執行
$ echo $?
顯示
1
文件說明
$ man bash
可以找到下面這一段說明
Special Parameters
The shell treats several parameters specially. These parameters may only be referenced; assignment to them is
not allowed.
...略...
? Expands to the exit status of the most recently executed foreground pipeline.
...略...
或是在
Bash Reference Manual / 3 Basic Shell Features / 3.4 Shell Parameters / 3.4.2 Special Parameters
可以找到下面這一段說明
?
($?) Expands to the exit status of the most recently executed foreground pipeline.
更多範例和說明請參考