version 1.16, 2000/03/28 23:40:05 |
version 1.17, 2000/06/26 02:43:31 |
|
|
where the script should quit if it cannot get a safe |
where the script should quit if it cannot get a safe |
temporary file. |
temporary file. |
.Bd -literal -offset indent |
.Bd -literal -offset indent |
TMPFILE=`mktemp /tmp/$0.XXXXXXXXXX` || exit 1 |
CMD=`basename $0` |
|
TMPFILE=`mktemp /tmp/$CMD.XXXXXXXXXX` || exit 1 |
echo "program output" >> $TMPFILE |
echo "program output" >> $TMPFILE |
.Ed |
.Ed |
.Pp |
.Pp |
In this case, we want the script to catch the error ourselves. |
In this case, we want the script to catch the error ourselves. |
.Bd -literal -offset indent |
.Bd -literal -offset indent |
TMPFILE=`mktemp -q /tmp/$0.XXXXXXXXXX` |
CMD=`basename $0` |
|
TMPFILE=`mktemp -q /tmp/$CMD.XXXXXXXXXX` |
if [ $? -ne 0 ]; then |
if [ $? -ne 0 ]; then |
echo "$0: Can't create temp file, exiting..." |
echo "$CMD: Can't create temp file, exiting..." |
exit 1 |
exit 1 |
fi |
fi |
.Ed |
.Ed |
|
|
is unable to create the file. |
is unable to create the file. |
In this case you can protect the part of the script thusly. |
In this case you can protect the part of the script thusly. |
.Bd -literal -offset indent |
.Bd -literal -offset indent |
TMPFILE=`mktemp /tmp/$0.XXXXXXXXXX` && { |
CMD=`basename $0` |
|
TMPFILE=`mktemp /tmp/$CMD.XXXXXXXXXX` && { |
# Safe to use $TMPFILE in this block |
# Safe to use $TMPFILE in this block |
echo data > $TMPFILE |
echo data > $TMPFILE |
... |
... |