From unknown Fri Aug 15 20:03:49 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30919: [grep: input file =?UTF-8?Q?'./x=E2=80=99?= is also the output] too late!.. have a null file. Resent-From: davidpbrown Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Fri, 23 Mar 2018 19:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30919 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 30919@debbugs.gnu.org X-Debbugs-Original-To: bug-grep@gnu.org Reply-To: openforum@davidpbrown.co.uk Received: via spool by submit@debbugs.gnu.org id=B.152183378715257 (code B ref -1); Fri, 23 Mar 2018 19:37:01 +0000 Received: (at submit) by debbugs.gnu.org; 23 Mar 2018 19:36:27 +0000 Received: from localhost ([127.0.0.1]:50039 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezSUF-0003y1-1s for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezSUC-0003xn-74 for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezSU5-0000rT-QD for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:18 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:50864) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ezSU5-0000rB-My for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezSU4-0005Nb-OR for bug-grep@gnu.org; Fri, 23 Mar 2018 15:36:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezSU1-0000k8-Je for bug-grep@gnu.org; Fri, 23 Mar 2018 15:36:16 -0400 Received: from solstice.linksky124.com ([184.173.222.93]:55936) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ezSU1-00082J-EG for bug-grep@gnu.org; Fri, 23 Mar 2018 15:36:13 -0400 Received: from [134.19.180.169] (port=33674 helo=[10.7.7.22]) by solstice.linksky124.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1ezSTK-002wcn-RP for bug-grep@gnu.org; Fri, 23 Mar 2018 15:35:31 -0400 From: davidpbrown Message-ID: Date: Fri, 23 Mar 2018 19:35:26 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-LinkSkyHosting-MailScanner-Information: Please contact the ISP for more information X-LinkSkyHosting-MailScanner-ID: 1ezSTK-002wcn-RP X-LinkSkyHosting-MailScanner: Found to be clean X-LinkSkyHosting-MailScanner-SpamCheck: X-LinkSkyHosting-MailScanner-From: openforum@davidpbrown.co.uk X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - solstice.linksky124.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - davidpbrown.co.uk X-Get-Message-Sender-Via: solstice.linksky124.com: authenticated_id: bartender@davidpbrown.co.uk X-Authenticated-Sender: solstice.linksky124.com: bartender@davidpbrown.co.uk X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hi, Surprised that the error is noted but only after the file gets clobbered. Example: ===================== echo "blah" > ./x grep -v 'foo' ./x > ./x # grep: input file './x’ is also the output # results with x being empty. ===================== Would have expected that catch to be caught ahead of writing a null in place of the original file. bash -v suggests RELEASE: 2.1 this on Linux Mint. Regards davidpbrown From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 23 16:22:00 2018 Received: (at control) by debbugs.gnu.org; 23 Mar 2018 20:22:00 +0000 Received: from localhost ([127.0.0.1]:50072 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezTCJ-0005NK-Vg for submit@debbugs.gnu.org; Fri, 23 Mar 2018 16:22:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54640 helo=mx1.redhat.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezTCH-0005Mz-A0; Fri, 23 Mar 2018 16:21:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6C57EBFF0; Fri, 23 Mar 2018 20:21:51 +0000 (UTC) Received: from [10.10.121.135] (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5827984445; Fri, 23 Mar 2018 20:21:51 +0000 (UTC) Subject: =?UTF-8?Q?Re:_bug#30919:_[grep:_input_file_'./x=e2=80=99_is_also_th?= =?UTF-8?Q?e_output]_too_late!.._have_a_null_file.?= To: openforum@davidpbrown.co.uk, 30919-done@debbugs.gnu.org References: From: Eric Blake Organization: Red Hat, Inc. Message-ID: Date: Fri, 23 Mar 2018 15:21:50 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Mar 2018 20:21:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Mar 2018 20:21:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) 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 From unknown Fri Aug 15 20:03:49 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: openforum@davidpbrown.co.uk Subject: bug#30919: closed (Re: bug#30919: [grep: input file =?UTF-8?Q?'./x=E2=80=99?= is also the output] too late!.. have a null file.) Message-ID: References: X-Gnu-PR-Message: they-closed 30919 X-Gnu-PR-Package: grep X-Gnu-PR-Keywords: notabug Reply-To: 30919@debbugs.gnu.org Date: Fri, 23 Mar 2018 20:22:04 +0000 Content-Type: multipart/mixed; boundary="----------=_1521836524-20694-1" This is a multi-part message in MIME format... ------------=_1521836524-20694-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #30919: [grep: input file './x=E2=80=99 is also the output] too late!.. hav= e a null file. which was filed against the grep package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 30919@debbugs.gnu.org. --=20 30919: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D30919 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1521836524-20694-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 30919-done) by debbugs.gnu.org; 23 Mar 2018 20:22:00 +0000 Received: from localhost ([127.0.0.1]:50070 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezTCJ-0005NI-Mr for submit@debbugs.gnu.org; Fri, 23 Mar 2018 16:21:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54640 helo=mx1.redhat.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezTCH-0005Mz-A0; Fri, 23 Mar 2018 16:21:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6C57EBFF0; Fri, 23 Mar 2018 20:21:51 +0000 (UTC) Received: from [10.10.121.135] (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5827984445; Fri, 23 Mar 2018 20:21:51 +0000 (UTC) Subject: =?UTF-8?Q?Re:_bug#30919:_[grep:_input_file_'./x=e2=80=99_is_also_th?= =?UTF-8?Q?e_output]_too_late!.._have_a_null_file.?= To: openforum@davidpbrown.co.uk, 30919-done@debbugs.gnu.org References: From: Eric Blake Organization: Red Hat, Inc. Message-ID: Date: Fri, 23 Mar 2018 15:21:50 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Mar 2018 20:21:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Mar 2018 20:21:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 30919-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) 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 ------------=_1521836524-20694-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 23 Mar 2018 19:36:27 +0000 Received: from localhost ([127.0.0.1]:50039 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezSUF-0003y1-1s for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezSUC-0003xn-74 for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezSU5-0000rT-QD for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:18 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:50864) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ezSU5-0000rB-My for submit@debbugs.gnu.org; Fri, 23 Mar 2018 15:36:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezSU4-0005Nb-OR for bug-grep@gnu.org; Fri, 23 Mar 2018 15:36:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezSU1-0000k8-Je for bug-grep@gnu.org; Fri, 23 Mar 2018 15:36:16 -0400 Received: from solstice.linksky124.com ([184.173.222.93]:55936) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ezSU1-00082J-EG for bug-grep@gnu.org; Fri, 23 Mar 2018 15:36:13 -0400 Received: from [134.19.180.169] (port=33674 helo=[10.7.7.22]) by solstice.linksky124.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1ezSTK-002wcn-RP for bug-grep@gnu.org; Fri, 23 Mar 2018 15:35:31 -0400 To: bug-grep@gnu.org From: davidpbrown Subject: =?UTF-8?Q?[grep:_input_file_'./x=e2=80=99_is_also_the_output]_too_l?= =?UTF-8?Q?ate!.._have_a_null_file.?= Message-ID: Date: Fri, 23 Mar 2018 19:35:26 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-LinkSkyHosting-MailScanner-Information: Please contact the ISP for more information X-LinkSkyHosting-MailScanner-ID: 1ezSTK-002wcn-RP X-LinkSkyHosting-MailScanner: Found to be clean X-LinkSkyHosting-MailScanner-SpamCheck: X-LinkSkyHosting-MailScanner-From: openforum@davidpbrown.co.uk X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - solstice.linksky124.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - davidpbrown.co.uk X-Get-Message-Sender-Via: solstice.linksky124.com: authenticated_id: bartender@davidpbrown.co.uk X-Authenticated-Sender: solstice.linksky124.com: bartender@davidpbrown.co.uk X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: openforum@davidpbrown.co.uk Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hi, Surprised that the error is noted but only after the file gets clobbered. Example: ===================== echo "blah" > ./x grep -v 'foo' ./x > ./x # grep: input file './x’ is also the output # results with x being empty. ===================== Would have expected that catch to be caught ahead of writing a null in place of the original file. bash -v suggests RELEASE: 2.1 this on Linux Mint. Regards davidpbrown ------------=_1521836524-20694-1--