Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created April 29, 2020 19:01
Show Gist options
  • Save miguelmota/09996561dda59c37442a2090e7fd3b92 to your computer and use it in GitHub Desktop.
Save miguelmota/09996561dda59c37442a2090e7fd3b92 to your computer and use it in GitHub Desktop.
Bash run processes in parallel and exit with status code example
#!/bin/bash
set -eux
declare -a arr=("backend" "frontend")
FAIL=0
for i in "${arr[@]}"
do
pkgpath="$(pwd)/packages/$i"
echo "Building $pkgpath"
(cd $pkgpath && npm run lint) &
done
for job in `jobs -p`
do
echo $job
wait $job || let "FAIL+=1"
done
if [ "$FAIL" == "0" ];
then
echo "Complete."
exit 0
else
echo "Completed with errors."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment