可以在脚本中禁用“set -e"吗? [英] Can “set -e” be disabled in a script?
本文介绍了可以在脚本中禁用“set -e"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 shell 脚本 main.sh 中做这样的事情.是否有可能?
I want to do something like this in a shell script main.sh. Is it possible?
设置 -e
******一些代码
取消设置 -e
******其他一些代码.
******some other code.
设置 -e
推荐答案
@Charles Duffy 在另一个线程上回答了这个问题.在以下情况下不退出 bash 脚本子脚本失败
@Charles Duffy on another thread answered this. not exit a bash script when one of the sub-script fails
set +e 撤消 set -e.然而,使用 set -e 通常是个坏主意;最好使用 ||在希望非零退出状态为致命的单个命令上退出.(如果你赶时间,跳过比喻到练习).– 查尔斯·达菲
set +e undoes set -e. However, using set -e is a bad idea in general; better to use || exit on individual commands where you want a nonzero exit status to be fatal. (Skip past the parable to the exercises if you're in a hurry). – Charles Duffy
这篇关于可以在脚本中禁用“set -e"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文