Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Oct 2006 10:30:57 -0500 (EST)
From:      Ensel Sharon <user@dhp.com>
To:        freebsd-questions@freebsd.org
Subject:   file redirect is destroying the file ?  Help!
Message-ID:  <Pine.LNX.4.21.0610301027260.2785-100000@shell.dhp.com>

next in thread | raw e-mail | index | archive | help

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.21.0610301027260.2785-100000>