5fb83a0a33
Some versions of bash do not initialise a variable with declare -a therefore with set -u bash can terminate the script. Be more verbose in declaring the array if it is not set Change-Id: I6ec2b6e986aeffe539a2ab93432fa7af9e5a4f5d
25 lines
355 B
Bash
Executable File
25 lines
355 B
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
set -o xtrace
|
|
|
|
if [ -z "${on_exit_hooks:-}" ]; then
|
|
on_exit_hooks=()
|
|
fi
|
|
|
|
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
|
|
}
|