`echo $?` 在 bash 中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18536693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does `echo $?` mean in bash?
提问by Ivan Prodanov
I came upon the following command:
我遇到了以下命令:
echo $?
what does that command do?
该命令有什么作用?
回答by Chris Pfohl
Echoes (prints) the exit value for the previous command.
回显(打印)上一个命令的退出值。
If it failed it will be different than zero (0
).
如果失败,它将不同于零 ( 0
)。
$ cd ~
$ echo $?
> 0
$ cd //whatever/
> bash: cd: //whatever/: No such file or directory
$ echo $?
> 1
Programs exit with a status code. Every program is unique and has a different set of failure codes, but it's universally acknowledged that 0
is the 'success' code.
程序以状态码退出。每个程序都是独一无二的,并且有一组不同的失败代码,但人们普遍认为这0
就是“成功”代码。