You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
324 B

# setup traps
declare -A traps
execute_traps() {
local t
for t in "${traps[@]}"; do
eval "$t"
trap 'execute_traps' EXIT
# kill jobs on exit
traps["kill jobs"]="jobs -r -p | xargs -r kill"
# do stuff
# now we don't want to wait until exit
eval "${traps["kill jobs"]}"
unset 'traps["kill jobs"]'