make temp files?

Guy Harris guy at gorodish.Sun.COM
Wed Sep 21 18:04:49 AEST 1988


> I was wondering if there is some "readymade" way that a shell can create a
> unique temporary file, as in the C routine "mktemp(XXXXX)".  Thanks!

Not exactly like "mktemp", but both the Bourne (and Korn) and C shells have a
variable "$$", which expands to the process ID of the shell.  This is what most
shell scripts use for temporary files, since the traditional UNIX trick for
making unique file names is to stuff the process ID of the creating process
into their names.  "mktemp" does other things, of course, that the shell script
would have to do itself.

BTW, you probably want to use "trap" in the Bourne or Korn shell, and "onintr"
in the C shell, to make sure the shell script cleans up its temporary files if
interrupted.  Not cleaning up your temporary files when interrupted is
considered Very Rude, both for programs and shell scripts.  (Yes, I know,
SunView windows don't clean up; I consider them Very Rude....)



More information about the Comp.unix.questions mailing list