[ale] Creating temporary files

John M. Mills jmills at TGA.com
Thu Dec 2 09:19:26 EST 1999


On Wed, 1 Dec 1999, Joe Knapka wrote:

> Is there a standard command-line utility
> that creates a unique temporary file and returns its name,
> say for use in a shell script? I've combed the
> man pages and checked the -Unix-System-Administration-
> Handbook- (Nemeth et al), but no such thing is
> mentioned. I'd be truly astonished if it didn't
> exist, though...

Joe - My method is shell-dependent (and my linux box is "filleted" this
morning - not a casualty; awaiting more SRAM -- so I can't look at a
sample), but my 'bash' scripts do something like this:

[.. make a name, say:]
FILENAME=/tmp/GIGO.$$

[.. use $FILENAME in the script, i.e.:

cat $FILENAME | lpr -

 .. then before exit ..] 
rm $FILENAME

The token '$$' is expanded to the PID, so FILENAME is unique for the
duration of the script's execution. If you just want some kind of 'in-use'
marker, you can create it by:

touch $TAGNAME.$$
[...]
rm $TAGNAME.$$

where TAGNAME is something easy to identify with your script, and of
course has to resolve to a directory in which your script has
write-permission.

Disclaimer: check the grammar, but you probably get the idea, and thanks
to others who showed me this trick.

  John Mills, Sr. Software Engineer
  TGA Technologies, Inc.
  100 Pinnacle Way, Suite 140
  Norcross, GA 30071-3633
  e-mail: jmills at tga.com
  Phone: 770-441-2100 ext.124 (voice)
         770-449-7740 (FAX)






More information about the Ale mailing list