Skip to content

Instantly share code, notes, and snippets.

@bhcleek
Last active April 19, 2016 04:12
Show Gist options
  • Save bhcleek/a630611dfe7ce07bbc23 to your computer and use it in GitHub Desktop.
Save bhcleek/a630611dfe7ce07bbc23 to your computer and use it in GitHub Desktop.
linux-osx.mktemp.sh
# try to create a temporary directory on osx first.
# `mktemp -d` works on OSX and Linux The basename will be random:
TMPDIR=$(mktemp -d)
# `mktemp -d -t FOO` is valid on OSX and uses TMPDIR, but will cause an error on Linux.
# `mktemp -d -t FOO.XXXXXX is valid on both: on Linux will do substitution of the Xs; but on OSX, the Xs are taken literally.
TMPDIR=$(mktemp -d -t ${PREFIX} 2>/dev/null || mktemp -d -t ${PREFIX}.XXXXXX)
# this can be shorted to
TMPDIR=$(mktemp -d "${TMPDIR-:/tmp/}$PREFIX.XXXXXX")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment