tempfile [-d DIR] [-p STRING] [-s STRING] [-m MODE] [-n FILE] [--directory=DIR] [--prefix=STRING] [--suffix=STRING] [--mode=MODE] [--name=FILE] [--help] [--version]
tempfile creates a temporary file in a safe manner. It uses tempnam(3) to choose the name and opens it with O_RDWR | O_CREAT | O_EXCL. The filename is printed on standard output. See tempnam(3) for the actual steps involved in directory selection.
The directory in which to create the file might be searched for in this order (but refer to tempnam(3) for authoritative answers):
An exit status of 0 means the temporary file was created successfully. Any other exit status indicates an error.
Exclusive creation is not guaranteed when creating files on NFS partitions. tempfile cannot make temporary directories. tempfile is deprecated; you should use mktemp(1) instead.
#!/bin/sh #[...] t=$(tempfile) || exit trap "rm -f -- '$t'" EXIT #[...] rm -f -- "$t" trap - EXIT exit