Skip to content

Instantly share code, notes, and snippets.

@smdern
Created February 18, 2016 23:59
Show Gist options
  • Save smdern/359f76af6ad0a0878da8 to your computer and use it in GitHub Desktop.
Save smdern/359f76af6ad0a0878da8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function check_status_code {
local name=$1
local status=$2
if [ $status -ne 0 ]; then
echo $name failed with status code $status
exit $status
fi
echo Success: $name with code $status
}
(sleep 8 ; echo "slow") &
slow=$!
(sleep 5 ; echo "med"; exit 1; echo "more stuff") &
med=$!
(sleep 2 ; echo "fast") &
fast=$!
wait $med
med_status=$?
wait $fast
fast_status=$?
wait $slow
slow_status=$?
check_status_code Fast $fast_status
check_status_code Med $med_status
check_status_code Slow $slow_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment