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

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

概述我在CentOS 6.5的init.d脚本中看到了很多奇怪的怪癖,但我在大多数脚本末尾看到的一种模式是 case "$1" in # ... commands hereesacexit $? “退出$?”的目的是什么?这里? 它使脚本将最后一个重要命令的返回码返回给调用init系统.每当命令退出时,其返回码存储在$?由壳. 实际上没有必要明确指定$?但脚本编写者可能只是将其包含在内,以 我在CentOS 6.5的init.d脚本中看到了很多奇怪的怪癖,但我在大多数脚本末尾看到的一种模式是

case "" in    # ... commands hereesacexit $?

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

解决方法 它使脚本将最后一个重要命令的返回码返回给调用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.

总结

以上是内存溢出为你收集整理的linux – 为什么许多init.d脚本以“exit $?”结尾?全部内容,希望文章能够帮你解决linux – 为什么许多init.d脚本以“exit $?”结尾?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1025785.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存