加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 为什么许多init.d脚本以“exit $?”结尾?

发布时间:2020-12-14 01:01:47 所属栏目:Linux 来源:网络整理
导读:我在CentOS 6.5的init.d脚本中看到了很多奇怪的怪癖,但我在大多数脚本末尾看到的一种模式是 case "$1" in # ... commands hereesacexit $? “退出$?”的目的是什么?这里? 解决方法 它使脚本将最后一个重要命令的返回码返回给调用init系统.每当命令退出时,
我在CentOS 6.5的init.d脚本中看到了很多奇怪的怪癖,但我在大多数脚本末尾看到的一种模式是

case "$1" in
    # ... commands here
esac
exit $?

“退出$?”的目的是什么?这里?

解决方法

它使脚本将最后一个重要命令的返回码返回给调用init系统.每当命令退出时,其返回码存储在$?由壳.

实际上没有必要明确指定$?但脚本编写者可能只是将其包含在内,以明确它打算做什么.

exit: exit [n]

Exit the shell.

Exits the shell with a status of N. If N is omitted,the exit status
is that of the last command executed.

我也希望你实际上并不意味着eend $? OpenRC:

eend retval [string ]

If retval does not equal 0 then output the string using eerror and !! in square > brackets at the end of the line. Otherwise output ok in square brackets at the end of the line. The value of retval is returned.

见source.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读