Bash - Exit parent script from child script

后端 未结 5 1740
盖世英雄少女心
盖世英雄少女心 2020-12-16 13:34

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 th

5条回答
  •  时光取名叫无心
    2020-12-16 14:31

    try..

    #normal flow
    [[ $(check_error_condition) ]] && /some/error_reporter.sh || exit 1
    

    so,

    • when the error_reporter will exit with exit status > 0 the parent will terminate too
    • if the error_reporter will exit with status = 0 the parent continues...

    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) ;)

提交回复
热议问题