mercredi 25 février 2015

Parent script continues when child exits with non-zero exit code


I have a script that calls another script. When the child script fails, I'd like the parent to fail as well.


In the child script child_1.sh, I have something like this:



if [ $SOME_BAD_CONDITION ] ; then
echo "Error message...."
exit 1
fi


In the parent, I have this:



#!/bin/bash
set -e
#...
bash ./child_1.sh
echo "continuing to next step..."
bash ./child_2.sh
bash ./child_3.sh
#...


I've set up my environment so that $SOME_BAD_CONDITION will always happen, and the script exits as expected and the error message does print, but the parent script continues: the message "continuing..." is printed and the next script begins executing.


I thought that having set -e would ensure that my parent script fails if any child script exists with a non-zero exit code, but that doesn't seem to be happening. I'm not sure what I got wrong here...



Aucun commentaire:

Enregistrer un commentaire