file redirect is destroying the file ? Help!

Ensel Sharon user at dhp.com
Mon Oct 30 15:31:04 UTC 2006


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" ?)



More information about the freebsd-questions mailing list