Two approaches -
First, you can examine the exit code of each of your inner scripts (test1.sh, test2.sh, ...) and decide whether to continue accordingly -
$?
Will return the exit code of the previous command. It will be 0
(zero) if the script exited without an error. Anything that is not 0
can be considered a failure. So you could so something like this -
./test1.sh # execute script
if [[ $? != 0 ]]; then exit; fi # check return value, exit if not 0
Alternatively, you could use the &&
bash operator which will only execute subsequent commands if the previous one passed -
./test1.sh && ./test2.sh && test3.sh
Only if test1.sh
returns an exit code of 0
(zero) will test2.sh
execute and the same goes for test3.sh
.
The first approach is good if you need to do some logging or cleanup between executing your scripts, but if you are only concerned that the execution should not continue if there was a failure then the &&
method would be they way I recommend.
Here is a related post dealing with the meaning behind &&