Bash - Exit parent script from child script

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

    Don't try to terminate the parent from the child. Instead call exit in the parent after the child script returned.

    if [ condition ]; then
      /path/to/child.sh
      exit 1
    fi
    

    or shorter

    [ condition ] && { /path/to/child.sh; exit 1; }
    

提交回复
热议问题