Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash run command at exit

If set -e is set, non-zero exit code during script run will terminate the execution.
To prevent immidient termination and add some logic to cleanup stuff, you may need to use trap command:

#!/usr/bin/env bash

set -e

function cleanup {
  echo "Removing $TMP_STUFF_DIR"
  rm  -f "$TMP_STUFF_DIR"
}

trap cleanup EXIT

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.