什么是$?在shell脚本中意味着什么?

amp*_*ent 0 unix shell

我遇到过$?我在其中一个shell脚本中进行集成(不是由我编写的).

只是想确认它意味着上一个命令的返回码.

用法类似于

runSomeCommand $VAR1 $VAR2 $VAR3

processResult $?
Run Code Online (Sandbox Code Playgroud)

Kar*_*ath 5

$? 是上次执行的命令的退出状态.

ls
....
echo $?
0

$ ls notexistingfile
ls: cannot access notexistingfile: No such file or directory

echo $?
2
Run Code Online (Sandbox Code Playgroud)