3 ms·
Beware that you can only have one EXIT handler. I've used this in the past figuring it's analogous to Go's `defer`, but unfortunately not. e.g this script:
by Ysx 9y ago
Beware that you can only have one EXIT handler. I've used this in the past figuring it's analogous to Go's `defer`, but unfortunately not.
e.g this script:
#!/bin/bash
trap 'echo Handler 1' EXIT
trap 'echo Handler 2' EXIT
Will only call 'Handler 2' on exit.
- orivej 9y agoI wrote `defer` (or rather `atexit`) for Bash: https://github.com/orivej/bash-traps/blob/master/atexit.sh https://github.com/orivej/bash-traps/blob/master/atexit.sh