[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] too paranoid?
From: |
John McKown |
Subject: |
[Help-bash] too paranoid? |
Date: |
Thu, 10 Mar 2016 09:43:48 -0600 |
I'm considering how to make sure that all the "temporary" files that I use
in a script are deleted when the script ends. I'm on Linux and don't really
care about cross platform compatibility. I.e. I don't care if it doesn't
work on Windows. I was thinking of doing something like:
#!/bin/bash
# Set up the TMPDIR environment variable, if it isn't already.
export TMPDIR=${TMPDIR:-${TMP}}
export TMPDIR=${TMPDIR:-/tmp}
temp1=$(mktemp) #create temporary file & get name
exec 11>${temp1} # make /dev/fd/11 point to said file
rm ${temp1} #unlink it, but it remains due to the above exec
temp1='/dev/fd/10' #and now use it nicely
#
# repeat above for temp2, using /dev/fd/12, and so on
process input-file.txt >${temp1}
process input-file2 >${temp2}
cat ${temp2} ${temp1} ${temp3} >./result-file.txt
Basically, I am making sure that my temporary files are unlinked almost
immediately after they have been created, but am able to access the data
due to the "exec ??>" opening the inode, via the name, and accessing it
using the /dev/fd/??
Is this going to fail on me, in UNIX, some day? Or is there some problem
which might come up by doing this?
Thanks.
--
A fail-safe circuit will destroy others. -- Klipstein
Maranatha! <><
John McKown