Last active
January 1, 2016 11:29
-
-
Save ezhuk/8138155 to your computer and use it in GitHub Desktop.
Create a temporary file the right way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This creates a temporary file and sets up a trap handler so that it gets | |
# deleted when the script exits. | |
BASENAME=$(which basename) | |
MKTEMP=$(which mktemp) | |
RM=$(which rm) | |
TMP_PREFIX=$($BASENAME "$0") | |
TMP_FILE=$($MKTEMP -t ${TMP_PREFIX}.XXXXXX) | |
trap '$RM -f $TMP_FILE' EXIT | |
# Do something with the file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment