linux – Shell脚本 – 如果子节点无法执行,如何终止父节点

我有一个shell脚本(父),它调用其他一些shell脚本.假设子shell脚本无法执行,那么也应该停止父shell脚本而不执行下一个子shell脚本.如何自动完成此过程?

例如:

main.sh
//inside the main.sh following code is there
child1.sh //executed successfully
child2.sh //error occurred
child3.sh //Skip this process
//end of main.sh

解决方法:

最简单的机制是:

set -e

这意味着只要子进程以失败状态退出,shell就会退出,除非状态作为条件的一部分进行测试.

例1

set -e
false                        # Exits
echo Not executed            # Not executed

例2

set -e
if false                     # Does not exit
then echo False is true
else echo False is false     # This is executed
fi

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐