blob: a4db39c22565ec2e539387051fee35fb79ce752d [file] [log] [blame]
#!/bin/bash
set -e
set -o xtrace
declare -a on_exit_hooks
on_exit()
{
for i in $(seq $((${#on_exit_hooks[*]} - 1)) -1 0)
do
eval "${on_exit_hooks[$i]}"
done
}
add_on_exit()
{
local n=${#on_exit_hooks[*]}
on_exit_hooks[$n]="$*"
if [[ $n -eq 0 ]]
then
trap on_exit EXIT
fi
}