tag 30919 notabug
thanks
On 03/23/2018 02:35 PM, davidpbrown wrote:
Hi,
Surprised that the error is noted but only after the file gets clobbered.
Example:
=====================
echo "blah" > ./x
grep -v 'foo' ./x > ./x
Unfortunately, there is nothing grep can do about this. The file was
already clobbered by your shell long before the shell even called exec()
to start grep.
I'm marking this as not a bug in grep's database, because there is
nothing grep can do about it. I'm sorry for your data loss, but this is
a naive beginner's mistake that multiple people have made for multiple
years.
The error message used in grep is reminiscent of the one used by 'sort
--o'; at least there, sort really does have a chance to warn you before
clobbering anything. But since 'grep -o' already means something
different than 'sort -o', I'm not sure if it is worth introducing a new
command line option, just so that:
grep -v foo --new-option-for-output=./x ./x
could properly warn (because in that style, it is grep, rather than the
shell, that would be opening stdout, and thus could avoid the
truncation). But even if we add a new option, it would take years
before it reaches common distros, and would still be a GNU extension not
present on other platforms, so you couldn't necessarily rely on it.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org