TEMPFILE(1) | General Commands Manual | TEMPFILE(1) |
tempfile - create a temporary file in a safe manner
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 mkstemps(3) to choose the name and opens it with O_RDWR | O_CREAT | O_EXCL. The filename is printed on standard output.
The directory in which to create the file might be searched for in this order:
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
27 Jun 2012 | Debian |