Created
August 1, 2019 16:38
-
-
Save twopoint718/39b0bf6d8be03ab784dfb00f67d1ef1a to your computer and use it in GitHub Desktop.
Ephemeral Tempfile in bash
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 | |
set -Eeuo pipefail | |
# Create a tempfile, get writeable (4) and readable (5) file descriptors. | |
# Immediately remove the actual temfile, making it inaccessible to other | |
# processes. This script will hold onto the descriptors until it exits. | |
tmpfile=$(mktemp) | |
echo "created $tmpfile" | |
exec 5<"$tmpfile" 4>"$tmpfile" | |
rm "$tmpfile" | |
printf "This is some text\n" >&4 | |
cat <&5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment