reading an unlinked file (was: cat, pipes, and filters)
Alex Martelli
alex at am.sublink.org
Wed Jun 5 08:40:44 AEST 1991
bp at chorus.fr (Bruno Pillard) writes:
...
:What about:
: ( /bin/rm $FILE ; sed s/"$ENTRY"/"$NEWENTRY"/ > $FILE ) < $FILE
:I understand that this may look harmful at first glance because of the
:/bin/rm of your precious file but it works perfectly for me under sh
:and (t)csh.
:
:Is there any problem using that construction ?
Normal Unix semantics, when a file is opened for reading (from the
outer shell, via the '<' redirection) and then unlinked (by the rm),
is that the file's directory entry is removed, but its contents are
still available to the process reading it; when it's finally closed,
assuming the link removed was the last one, its space will be reused.
If, however, $FILE stands in for a file remotely mounted in such a
way that usual semantics are not necessarily preserved (I'm thinking
of NFS), then I'm afraid you might lose it, if it's large enough not
to have been entirely read at the moment it's rm'ed. I can't test
here at home, and I hope somebody will show why this is wrong, but...
--
Alex Martelli - (home snailmail:) v. Barontini 27, 40138 Bologna, ITALIA
Email: (work:) martelli at cadlab.sublink.org, (home:) alex at am.sublink.org
Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434;
Fax: ++39 (51) 366964 (work only), Fidonet: 2:332/407.314 (home only).
More information about the Comp.unix.shell
mailing list