16.16 Picking a Unique Filename AutomaticallyShell scripts, aliases, and other programs can need temporary files to hold data used later. If the program will be run more than once, or if the temp file needs to stay around after the program is done, you need some way to make a unique filename. One way is with the shell's process ID number (38.3 ) , available in the $$ parameter and often used in the /tmp directory . (21.3 ) You might name a file /tmp/MYPROG$$ ; the shell will turn that into something like /tmp/MYPROG1234 or /tmp/MYPROG28471 . If your program needs more than one temporary file, add an extra unique character to the names:
errs=/tmp/MYPROGe$$ output=/tmp/MYPROGo$$ Remember the 14-character filename limit on some older UNIXes. $$ usually makes two to five characters. If your UNIX doesn't have a
date
command
that takes a
% Use a temp=foo.`date +'%m%d'` Article 21.3 shows another system for temporary files. - |
|