I have written a script like this:
error = 0
do_background() {
command $1 || {
echo "command has failed with status $?"
((error++));
}
}
for i in 1..20; do
do_background $i &
done
wait
if [[ $error != 0 ]]; then
echo "Detected $error errors"
exit 1
fi
If I run it with the -x
option here is the result:
+ command 1
+ echo 'command has failed with status 1'
command has failed with status 1
+ (( error++ ))
+ [[ 0 != 0 ]]
My question is why error isn't greater than zero.