Skip to content

Instantly share code, notes, and snippets.

@michaelhood
Created February 18, 2013 03:21
Show Gist options
  • Save michaelhood/4974940 to your computer and use it in GitHub Desktop.
Save michaelhood/4974940 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
trap outdirty SIGINT SIGTERM
function out() {
echo "out, cleaning up"
}
function outgood() {
echo "success"
}
function outdirty() {
echo "got killed"
out
}
function outfail() {
echo "got fail: $@"
out
}
function j1() {
{ for i in {1..5}; do echo j1: $i; sleep 1; done && echo "stage j1"; } || outfail "j1 sad" $?
}
function j2() {
{ for i in {1..5}; do echo j2: $i; sleep 1; done && echo "stage j2"; } || outfail "j2 sad" $?
}
function j3() {
{ for i in {1..5}; do echo j3: $i; sleep 1; done && echo "stage j3"; } || outfail "j3 sad" $?
}
{ j1; } &
{ j2; } &
{ j3; } &
wait
outgood
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment