Bash - Exit parent script from child script

后端 未结 5 1745
盖世英雄少女心
盖世英雄少女心 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:33

    Depending on your needs, using set -e at the top of your script might be a good solution. This will automatically cause the script to exit if any commands (e.g., your error checking script) exit with a non-zero exit code (https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/)

    Note that there are some common commands that have non zero exit codes under normal circumstance.

提交回复
热议问题