有关 shell 脚本的帮助
我正在创建一个 init.d 服务,并正在阅读一些脚本以供参考。我在骨架中发现了这个:
这个片段有什么作用?我知道这是一个 switch:case。我问的是案中案。
case "$1" in
start)
echo test
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
PS:请原谅这个标题,我想不出更好的名字了,
谢谢。
I was creating a init.d service, and was reading a few scripts for reference. I found this one in a skeleton:
What does this snippet do? I get that this is a switch:case. I am asking about the case within the case.
case "$1" in
start)
echo test
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
PS: Excuse the title, I couldn't think of a better name
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来实际的脚本可能有比“回声测试”更实质性的内容。 $?是此脚本中 echo 命令返回的退出代码。内部 case 语句打印适合终止代码的日志消息。 0|1 最有可能是成功。 2 可能是一个错误。
Seems like the actual script might have had something more substantial than 'echo test'. $? is the exit code returned by the echo command in this script. The inner case statement prints the log message that is appropriate for the termination code. 0|1 most likely is success. 2 is probably an error.
$?保存最后执行的命令的退出代码。
如果 0 - 没有错误。
$? holds the exit code of the last executed command.
If 0 - there were no errors.