In the context of mktemp, "safe" means protected from inadvertent interference from other programs, especially as a result of name collision. mktemp tries to give you some assurance that even though your file is in a file system shared with numerous other programs, your script will probably be the only one interacting with the file. mktemp handles this for you in three ways:
- It creates names with random characters so they are unlikely to have the same name as other programs (or other running instances of the same script).
- It sets the permissions on the file so that it is only readable and writable by its owner, limiting the number of other programs which could disrupt it.
- It checks that the name isn't already in use. In other words, it checks that the file doesn't already exist.
A dry-run of mktemp can't handle permissions for you (#2), but that's easy enough to do yourself with chmod if you want.
The problem the mktemp documentation is warning you about is #3. While the invocation of mktemp in the current script will ensure the name isn't in use yet, it doesn't communicate this to other programs. Therefore, another program, or another invocation of the same script running concurrently, may invoke mktemp again and get the same temporary file path.
The only time you may want to use mktemp --dry-run is is for some rare programs which will not allow their output file or directory to exist already. In these circumstances, you may want to decrease the likelihood of name collision through:
- Increasing the number of random characters in the filename (mktemp function #1, above).
- Minimize the amount of time between the invocation of mktemp and the moment when the file is created. Similarly, you can let mktemp create the file, and delete it just before another command will create a file at the temporary path.