I'm writing a shell script, and I need to create a temporary file with a certain extension.
I've tried
tempname=`basename $0`
TMPPS=`mktemp /tmp/${tempname}.XXXXXX.ps` || exit 1
and
tempname=`basename $0`
TMPPS=`mktemp -t ${tempname}` || exit 1
neither work, as the first creates a file name with a literal "XXXXXX" and the second doesn't give an option for an extension.
I need the extension so that preview won't refuse to open the file.
Edit: I ended up going with a combination of pid and mktemp in what I hope is secure:
tempname=`basename $0`
TMPTMP=`mktemp -t ${tempname}` || exit 1
TMPPS="$TMPTMP.$$.ps"
mv $TMPTMP $TMPPS || exit 1
It is vulnerable to a denial of service attack, but I don't think anything more severe.