Unlinked temp files in sh scripts
David Elliott
dce at Solbourne.COM
Sat Apr 29 07:01:52 AEST 1989
In article <1015 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>In article <871 at marvin.Solbourne.COM> dce at Solbourne.com (David Elliott) writes:
>| exec 3>temp.$$ 4<temp.$$
>| 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 at Solbourne.COM
...!{boulder,nbires,sun}!stan!dce
More information about the Comp.unix.wizards
mailing list