I know this is a common question and I have even seen answers to it before, but I cannot remember what they were nor find them.
#!/usr/bin/env bash
set -m # allow for job control
EXIT_CODE=0 # exit code of overall script
function foo() {
for job in `jobs -p`; do
echo "PID => ${job}"
wait ${job} || { echo "At least one test failed with exit code => $?" ; EXIT_CODE=1; }
done
}
trap 'foo' CHLD
My question concerns this line:
wait ${job} || { echo "At least one test failed with exit code => $?" ; EXIT_CODE=1; }
If wait ${job} yields a non-zero exit code I'd like to echo out the statement and then do an assignment (assigning 1 to EXIT_CODE).
I don't believe my syntax is correct. I am not getting any obvious errors, but I am pretty certain it's not correct because the statement is not being echoed. But I am still exiting with an exit code of 1.
wait...line already looks good to me. I assume you've not provided your entire script, though, so there's only the posted context to review.