Bash-从子脚本退出父脚本 [英] Bash - Exit parent script from child script
问题描述
我有一个Bash父脚本,该Bash父脚本在意外输入时会调用记录错误的错误记录子脚本.我还希望在发生错误并调用错误脚本时停止执行.但是,如果我从错误处理脚本中调用exit
,它不会停止父脚本的执行.我该如何停止孩子的父脚本?
I have a Bash parent script that on unexpected input calls an error logging child script that logs the error. I also want the execution to halt when the error occurs and the error script is called. But if I call exit
from the error handling script it does not stop the parent script from executing. How may I go about stopping a parent script from a child?
推荐答案
尝试..
#normal flow
[[ $(check_error_condition) ]] && /some/error_reporter.sh || exit 1
所以
- 当error_reporter将以退出状态> 0退出时,父级也会终止
- 如果error_reporter将以状态= 0退出,则父级继续...
您不想要stop the parent from a child
(父母通常不喜欢这种行为):),您反而想要tell to parent - need stop
,他会自行停止(如果需要);)
You don't want stop the parent from a child
(the parents usually don't like this behavior) :), you instead want tell to parent - need stop
and he will stop itself (if want) ;)
这篇关于Bash-从子脚本退出父脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!