Skip to content

Instantly share code, notes, and snippets.

@mthomure
Created November 8, 2017 02:08
Show Gist options
  • Save mthomure/1e77808876ab09e69d58fc98f7b1c508 to your computer and use it in GitHub Desktop.
Save mthomure/1e77808876ab09e69d58fc98f7b1c508 to your computer and use it in GitHub Desktop.
Create temp dir in bash script
#!/bin/bash
# See also: https://stackoverflow.com/questions/10982911/creating-temporary-files-in-bash
# Create temporary directory.
mydir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXXXX")
# Remove on exit.
trap "rm -rf $mydir" EXIT
# YOUR SCRIPT HERE...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment