# if you run a script with -e that produces state that you want to clean up if anything goes wrong in your script, this helps: trap 'handle_error' ERR handle_error () { echo "an error has occured, let’s clean up some stuff" # rm some-stuff.txt }