Getting HUPed

Kris Stephens [Hail Eris!] krs at uts.amdahl.com
Fri Mar 22 05:47:26 AEST 1991


Here's how I handle tempfiles...

Assume I need two of them and that I'll use $$ as part of the filename
to allow for multiple copies of the script to run simultaneously.

--- start junk (a sh or ksh script) ---
:
# Make and load a couple of temp files and trap for them to
# be removed automagically on exit.
TEMP1=/usr/tmp/junk1.$$
TEMP2=/usr/tmp/junk2.$$
trap 'rm -f $TEMP1 $TEMP2' 0 1 2 3 14 15

ls > $TEMP1 2>$TEMP2

echo "number of files: \c"; wc -l < $TEMP1
[ -s $TEMP2 ] && echo "number of error messages: \c"; wc -l < $TEMP2
--- end junk (a sh or ksh script) ---

The thing about the trapped command is that you don't need to issue
an exit from within the command-series.  The sh (or ksh) will simply
execute the command on its merry way out.

Don't use $$ in filenames of tempfiles without loading the resulting
filename into a simple variable.  $$ changes value when you fork a
subshell, for instance.  This *might* be what led (combined with the
exit in the trapped command-series) to the cascade of processes.

...Kris
-- 
Kristopher Stephens, | (408-746-6047) | krs at uts.amdahl.com | KC6DFS
Amdahl Corporation   |                |                    |
     [The opinions expressed above are mine, solely, and do not    ]
     [necessarily reflect the opinions or policies of Amdahl Corp. ]



More information about the Comp.unix.shell mailing list