Last active
April 8, 2020 18:24
-
-
Save multun/962a301694de3b4738e27242becee096 to your computer and use it in GitHub Desktop.
bash space safe cleanup hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__cleanup_hook_i=0 | |
__cleanup_hook () { | |
for ((i=__cleanup_hook_i - 1; i >= 0; i--)); do | |
eval "\"\${__cleanup_hook_action_${i}[@]}\"" | |
done | |
} | |
trap __cleanup_hook EXIT | |
register_cleanup () { | |
eval "__cleanup_hook_action_$((__cleanup_hook_i++))=( \"\$@\" )" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment