Date: Mon, 30 Oct 2006 10:50:51 -0500 From: DAve <dave.list@pixelhammer.com> To: freebsd-questions@freebsd.org Subject: Re: file redirect is destroying the file ? Help! Message-ID: <45461F5B.80700@pixelhammer.com> In-Reply-To: <Pine.LNX.4.21.0610301027260.2785-100000@shell.dhp.com> References: <Pine.LNX.4.21.0610301027260.2785-100000@shell.dhp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Ensel Sharon wrote: > I have a script that, among other things, removes a line from > /etc/ftpchroot. > > I do this with this method: > > > cat /etc/ftpchroot | grep -v $remove > /etc/ftpchroot > > > Easy. You cat all of the file except the line you want to remove, and > redirect it back to itself. > > The problem is, about 50% of the time, I end up with an empty ftpchroot > file. It is zero bytes. This obviously has nothing to do with a bad > variable, since if it wasn't there, the starting file and ending file > would just be identical. > > Instead, I get an empty file. I have reproduced this with other files in > other places - works some of the time, other times gives me an empty file. > > What gives ? > > (note, I know a lot of ways to work around this - so I'm not so much > asking how to fix this, as I am asking "why does this happen" ?) I can't answer your question except to say that I have always redirected to a tmp file, and then replaced the original after safely closing it and testing the tmp file for whatever results I expect. Just dumping output to overwrite the file I am currently reading was always bad juju in my book. DAve -- Three years now I've asked Google why they don't have a logo change for Memorial Day. Why do they choose to do logos for other non-international holidays, but nothing for Veterans? Maybe they forgot who made that choice possible.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45461F5B.80700>