I have 2 shell scripts, namely script A and script B.
I have both of them “set -e”, telling them to stop upon error.
However, when script A call script B, and script B had an error and stopped, script A didn’t stop.
What can I stop the mother script when the child script dies?
It should work as you’d expect. For example:
In
mother.sh:In
child.sh:Calling
mother.sh:Why is it not working for you?
One possible situation where it won’t work as expected is if you specified
-ein the shabang line (#!/bin/bash -e) and passed the script directly tobashwhich will treat that as a comment.For example, if we change
mother.shto:Notice how it behaves differently depending on how you call it:
Explicitly calling
set -ewithin the script will solve this problem.