Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!ukc!axion!stc!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.wizards Subject: Re: Unlinked temp files in sh scripts Message-ID: <751@root44.co.uk> Date: 2 May 89 13:50:44 GMT References: <871@marvin.Solbourne.COM> Reply-To: gwc@root.co.uk (Geoff Clare) Organization: UniSoft Ltd, London, England Lines: 26 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 rm -f temp.$$ A neat idea, but unfortunately it suffers from one big problem - those hard-coded file descriptor numbers. Suppose I execute a shell script which uses this trick (although I am unaware of it) and I use file descriptor 3 on the command line for some reason. The result could be disastrous. The idea could be made to work by having the script execute a program which returns two free file descriptor numbers. But is it worth the bother, just to avoid a "trap" statement? A neater solution could be had if there was a predefined shell variable (like $$, $#, etc.) giving the next available file descriptor. Maybe the Korn shell has such a thing? -- Geoff Clare UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH gwc@root.co.uk ...!mcvax!ukc!root44!gwc +44-1-315-6600 FAX: +44-1-315-6622