$的含义?(美元问号)在 shell 脚本中 [英] Meaning of $? (dollar question mark) in shell scripts

查看:74
本文介绍了$的含义?(美元问号)在 shell 脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做什么

echo $?

shell 编程中的意思?

解决方案

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

例如命令 true 总是返回状态 0false 总是返回状态 1:

真回声 $?# 回显 0错误的回声 $?# 回声 1

来自手册:(可通过在 shell 中调用 man bash 访问)

<块引用>

$? 扩展到最近执行的前台管道的退出状态.

按照惯例,退出状态 0 表示成功,非零返回状态表示失败.详细了解退出状态维基百科.>

还有其他类似的特殊变量,您可以在本在线手册中看到:https://www.gnu.org/s/bash/manual/bash.html#Special-Parameters

What does

echo $?

mean in shell programming?

解决方案

This is the exit status of the last executed command.

For example the command true always returns a status of 0 and false always returns a status of 1:

true
echo $? # echoes 0
false
echo $? # echoes 1

From the manual: (acessible by calling man bash in your shell)

$?       Expands to the exit status of the most recently executed foreground pipeline.

By convention an exit status of 0 means success, and non-zero return status means failure. Learn more about exit statuses on wikipedia.

There are other special variables like this, as you can see on this online manual: https://www.gnu.org/s/bash/manual/bash.html#Special-Parameters

这篇关于$的含义?(美元问号)在 shell 脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆