Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!pprg.unm.edu!hc!lll-winken!uunet!mcvax!hp4nl!phigate!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.wizards Subject: Re: Unlinked temp files in sh scripts Message-ID: <1015@philmds.UUCP> Date: 26 Apr 89 17:06:00 GMT References: <871@marvin.Solbourne.COM> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 70 In article <871@marvin.Solbourne.COM> dce@Solbourne.com (David Elliott) writes: | |This is a trick that Dave Hitz (hitz@auspex.com) and I worked |out last year: | | exec 3>temp.$$ 4&3 | |After this has been done, fd 4 is still a read descriptor |pointing at the beginning of the temp file, so you can |read the data in the file by redirecting from fd 4, or, |if you need to read it multiple time, by dup'ing fd 4 |("exec 5<&4", for example, to copy it to fd 5). This doesn't work, since 5<&4 effectively is dup2(4,5). And although this gives you a new descriptor, it will have only one seek pointer in the file. This means if you read to EOF on 4, you're also on EOF on 5. Example: ----------- Start of sample program ----------- #! /bin/sh exec 3>temp.$$ 4&3 <