Created
April 29, 2020 19:01
-
-
Save miguelmota/09996561dda59c37442a2090e7fd3b92 to your computer and use it in GitHub Desktop.
Bash run processes in parallel and exit with status code example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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