大多数shell在其中存储前一个run命令的退出代码,
$?因此您可以存储或显示它。
$ ./a.out$ echo $? # note - after this command $? contains the exit pre of echo!
要么
$ ./a.out$ exit_pre=$? # save the exit pre in another shell variable.
请注意,在Linux下,尽管您返回,但
int通常只有小于126的值才可以安全使用。保留较高的值,以记录其他在尝试运行命令时可能发生的错误,或者记录哪个信号(如果有)终止了程序。



