Skip to content

Instantly share code, notes, and snippets.

@chrolis
Created June 2, 2017 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrolis/59450239e372a1211392e16954948404 to your computer and use it in GitHub Desktop.
Save chrolis/59450239e372a1211392e16954948404 to your computer and use it in GitHub Desktop.
temp directory snippet
#!/usr/bin/env bash
unset tmpdir
atexit() {
[[ -n ${tmpdir-} ]] && rm -rf "$tmpdir"
}
trap atexit EXIT
trap 'trap - EXIT; atexit; exit -1' INT PIPE TERM
tmpdir=$(mktemp -d "/tmp/${0##*/}.tmp.XXX")
echo $tmpdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment