'set -e' 在 bash 中有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55361549/
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 'set -e' do in bash?
提问by Andy
I've received a comment on a merge request saying that I need to use 'set -e' to do error handling, but I'm struggling to find anything that actually details what it does.
我收到了关于合并请求的评论,说我需要使用“set -e”来进行错误处理,但我正在努力寻找任何能够详细说明它的作用的内容。
回答by Markus Appel
From http://linuxcommand.org/lc3_man_pages/seth.html:
从http://linuxcommand.org/lc3_man_pages/seth.html:
-e Exit immediately if a command exits with a non-zero status.
回答by Xilpex
If you type help set
in your bash terminal, here is the output:
如果您help set
在 bash 终端中输入,则输出如下:
-e Exit immediately if a command exits with a non-zero status.
This means that the set -e
command stops the a script from executing if a command or pipeline runs into an error.
这意味着set -e
如果命令或管道遇到错误,该命令会停止执行脚本。