Skip to content

Instantly share code, notes, and snippets.

@stevenhao
Created August 2, 2016 19:03
Show Gist options
  • Save stevenhao/65ae51cc13c51f62d4c3abd0eecc9335 to your computer and use it in GitHub Desktop.
Save stevenhao/65ae51cc13c51f62d4c3abd0eecc9335 to your computer and use it in GitHub Desktop.
initTrap() {
TRAPCMD="initTrap"
}
pushTrap() {
if [ -z "$TRAPCMD" ]; then
initTrap
fi
TRAPCMD="$TRAPCMD;$1"
trap "$TRAPCMD" SIGINT # overrides previous trap
}
run() {
$1 | sed -e "s/^/[$2]: /" &
pushTrap "echo killing $2 && kill $!"
}
run ./a.sh a
run ./b.sh b
wait
run ./a.sh a2
run ./b.sh b2
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment