Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!oliveb!amdahl!krs From: krs@uts.amdahl.com (Kris Stephens [Hail Eris!]) Newsgroups: comp.unix.shell Subject: Re: Getting HUPed Message-ID: Date: 21 Mar 91 19:47:26 GMT References: <53767@mirror.tmc.com> Reply-To: krs@amdahl.uts.amdahl.com (Kris Stephens [Hail Eris!]) Distribution: na Organization: Amdahl Corporation, Sunnyvale CA Lines: 34 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@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. ]