Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!boulder!stan!dce From: dce@Solbourne.COM (David Elliott) Newsgroups: comp.unix.wizards Subject: Re: Unlinked temp files in sh scripts Message-ID: <908@marvin.Solbourne.COM> Date: 28 Apr 89 21:01:52 GMT References: <871@marvin.Solbourne.COM> <1015@philmds.UUCP> Reply-To: dce@Solbourne.com (David Elliott) Organization: Solbourne Computer Inc., Longmont, Colorado Lines: 30 In article <1015@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes: >In article <871@marvin.Solbourne.COM> dce@Solbourne.com (David Elliott) writes: >| exec 3>temp.$$ 4| rm -f temp.$$ >For C programs this is already a common technique when dealing with >temp files: open a file (giving you a descriptor), then unlink it. As >long as the file is not closed, it still can be accessed via the >descriptor. Perhaps it is not so commonly used in sh scripts. Give this man a cigar! Seriously, I guess I should have pointed out that the trick here was to duplicate the well-known C technique in shell. In my 6 years as a shell programmer, I had never seen this technique applied to the shell (which is why I felt that it was useful to post the idea). In general, shell programmers either trap 0 (exit from shell), trap a whole slew of signals, or just assume that the shell script will exit cleanly. Most people assume that programming in shell is a bad idea because of all the things you can't do. I enjoy finding ways to do things that appear to be impossible to do in sh, if only to say "nyaah" to people who make statements like "you shouldn't program in sh because it isn't a structured programming language" (not that this trick disproves that, but...) -- David Elliott dce@Solbourne.COM ...!{boulder,nbires,sun}!stan!dce