[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#30919: [grep: input file './x’ is also the output] too late!.. have
bug#30919: [grep: input file './x’ is also the output] too late!.. have a null file.
Fri, 23 Mar 2018 15:21:50 -0500
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0
tag 30919 notabug
On 03/23/2018 02:35 PM, davidpbrown wrote:
Surprised that the error is noted but only after the file gets clobbered.
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
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