If a Bash script has set -e, and a command in the script returns an error, how can I do some cleanup before the script exits?
set -e
For example:
sh version of devguydavid's answer.
sh
#!/bin/sh set -e cleanup() { echo "Removing /tmp/foo" rm -r /tmp/foo } trap cleanup EXIT mkdir /tmp/foo asdffdsa #Fails
ref: shellscript.sh