From unknown Thu Jun 19 16:19:35 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#18449 <18449@debbugs.gnu.org> To: bug#18449 <18449@debbugs.gnu.org> Subject: Status: "cat x >> x" error even when x is empty Reply-To: bug#18449 <18449@debbugs.gnu.org> Date: Thu, 19 Jun 2025 23:19:35 +0000 retitle 18449 "cat x >> x" error even when x is empty reassign 18449 coreutils submitter 18449 Vincent Lefevre severity 18449 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 11 09:01:19 2014 Received: (at submit) by debbugs.gnu.org; 11 Sep 2014 13:01:19 +0000 Received: from localhost ([127.0.0.1]:37531 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS3zz-0004if-6n for submit@debbugs.gnu.org; Thu, 11 Sep 2014 09:01:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41562) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS3zv-0004iU-Tj for submit@debbugs.gnu.org; Thu, 11 Sep 2014 09:01:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XS3zn-0000sR-TR for submit@debbugs.gnu.org; Thu, 11 Sep 2014 09:01:15 -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.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:41679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS3zn-0000sM-R4 for submit@debbugs.gnu.org; Thu, 11 Sep 2014 09:01:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS3zi-0002RM-Td for bug-coreutils@gnu.org; Thu, 11 Sep 2014 09:01:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XS3zZ-0000pN-8W for bug-coreutils@gnu.org; Thu, 11 Sep 2014 09:01:02 -0400 Received: from ypig.lip.ens-lyon.fr ([140.77.13.48]:52501) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS3zZ-0000k4-0W for bug-coreutils@gnu.org; Thu, 11 Sep 2014 09:00:53 -0400 Received: from vlefevre by ypig.lip.ens-lyon.fr with local (Exim 4.84) (envelope-from ) id 1XS3zQ-0000Qh-Ge; Thu, 11 Sep 2014 15:00:44 +0200 Date: Thu, 11 Sep 2014 15:00:44 +0200 From: Vincent Lefevre To: bug-coreutils@gnu.org Subject: "cat x >> x" error even when x is empty Message-ID: <20140911130044.GB4859@ypig.lip.ens-lyon.fr> Mail-Followup-To: Vincent Lefevre , bug-coreutils@gnu.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Mailer-Info: http://www.vinc17.net/mutt/ User-Agent: Mutt/1.5.23-6361-vl-r59709 (2014-07-25) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). 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.15 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 (-----) With coreutils 8.23 under Debian/unstable: ypig% : > x ypig% cat x >> x cat: x: input file is output file ypig% POSIXLY_CORRECT=1 cat x >> x cat: x: input file is output file while there's no reason to return an error in this case: the file should just remain empty. Using the same file for input and output isn't disallowed by POSIX, AFAIK. This may not seem really useful here, but this can potentially break scripts with things like: cat "$foo" >> "$bar" where "$foo" may be the same file as "$bar" only if it is empty. BTW, when x isn't empty, I wonder whether an error is correct if POSIXLY_CORRECT is set. The result will typically depend on the implementation and possibly be non-deterministic, but POSIX doesn't seem to allow an error (except FS errors, such as disk full). -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon) From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 11 09:20:33 2014 Received: (at 18449) by debbugs.gnu.org; 11 Sep 2014 13:20:33 +0000 Received: from localhost ([127.0.0.1]:37628 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS4Ia-0005I5-KS for submit@debbugs.gnu.org; Thu, 11 Sep 2014 09:20:32 -0400 Received: from mail1.vodafone.ie ([213.233.128.43]:15548) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS4IY-0005Hw-Mo for 18449@debbugs.gnu.org; Thu, 11 Sep 2014 09:20:31 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBAE2hEVRtTJWM/2dsb2JhbAANUtEqgyABgSeEewEBAQMBMgFLCwsNCwkWDwkDAgECAUUGAQwIAQGINg2oL5Y4ARePVIRMAQSkaJEvgzoBAQE Received: from unknown (HELO [192.168.1.79]) ([109.76.149.140]) by mail1.vodafone.ie with ESMTP; 11 Sep 2014 14:20:07 +0100 Message-ID: <5411A186.8030408@draigBrady.com> Date: Thu, 11 Sep 2014 14:20:06 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Vincent Lefevre , 18449@debbugs.gnu.org Subject: Re: bug#18449: "cat x >> x" error even when x is empty References: <20140911130044.GB4859@ypig.lip.ens-lyon.fr> In-Reply-To: <20140911130044.GB4859@ypig.lip.ens-lyon.fr> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18449 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: 0.0 (/) On 09/11/2014 02:00 PM, Vincent Lefevre wrote: > With coreutils 8.23 under Debian/unstable: > > ypig% : > x > ypig% cat x >> x > cat: x: input file is output file > ypig% POSIXLY_CORRECT=1 cat x >> x > cat: x: input file is output file > > while there's no reason to return an error in this case: the file > should just remain empty. Using the same file for input and output > isn't disallowed by POSIX, AFAIK. > > This may not seem really useful here, but this can potentially break > scripts with things like: > > cat "$foo" >> "$bar" > > where "$foo" may be the same file as "$bar" only if it is empty. I'm struggling to see that use case TBH. > BTW, when x isn't empty, I wonder whether an error is correct if > POSIXLY_CORRECT is set. The result will typically depend on the > implementation and possibly be non-deterministic, but POSIX doesn't > seem to allow an error (except FS errors, such as disk full). This is just a protection against non deterministic usage. I.E. if there is data in the file then it'll probably run until the file system is exhausted. This is what happens on FreeBSD BTW, though I see that Solaris has the same protections as GNU. I wouldn't be on for removing this protection which has existed from the initial GNU implementation. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 11 10:56:17 2014 Received: (at 18449) by debbugs.gnu.org; 11 Sep 2014 14:56:18 +0000 Received: from localhost ([127.0.0.1]:38214 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS5nE-0007wj-Hi for submit@debbugs.gnu.org; Thu, 11 Sep 2014 10:56:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15085) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS5nB-0007wZ-E1 for 18449@debbugs.gnu.org; Thu, 11 Sep 2014 10:56:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8BEuBBj020732 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 11 Sep 2014 10:56:11 -0400 Received: from [10.3.113.7] ([10.3.113.7]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8BEuAsq014489; Thu, 11 Sep 2014 10:56:11 -0400 Message-ID: <5411B80A.4040707@redhat.com> Date: Thu, 11 Sep 2014 08:56:10 -0600 From: Eric Blake Organization: Red Hat, Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= , Vincent Lefevre , 18449@debbugs.gnu.org Subject: Re: bug#18449: "cat x >> x" error even when x is empty References: <20140911130044.GB4859@ypig.lip.ens-lyon.fr> <5411A186.8030408@draigBrady.com> In-Reply-To: <5411A186.8030408@draigBrady.com> OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="khWept0TPVbRObsv8Sk4csecodFnJHSpa" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Spam-Score: -7.5 (-------) X-Debbugs-Envelope-To: 18449 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -7.5 (-------) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --khWept0TPVbRObsv8Sk4csecodFnJHSpa Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 09/11/2014 07:20 AM, P=C3=A1draig Brady wrote: >> while there's no reason to return an error in this case: the file >> should just remain empty. Testing for an empty file is enough of an additional special case over the existing check for same files that I don't think it is worth it. >> BTW, when x isn't empty, I wonder whether an error is correct if >> POSIXLY_CORRECT is set. The result will typically depend on the >> implementation and possibly be non-deterministic, but POSIX doesn't >> seem to allow an error (except FS errors, such as disk full). I've raised this as an issue for the Austin Group to rule on: http://austingroupbugs.net/view.php?id=3D876 >=20 > This is just a protection against non deterministic usage. > I.E. if there is data in the file then it'll probably run > until the file system is exhausted. This is what happens > on FreeBSD BTW, though I see that Solaris has the same > protections as GNU. I'm hoping that POSIX standardizes the existing practice of forbidding known disk-filling operations. >=20 > I wouldn't be on for removing this protection which > has existed from the initial GNU implementation. My thoughts, too. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --khWept0TPVbRObsv8Sk4csecodFnJHSpa Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJUEbgKAAoJEKeha0olJ0NqOTEH/1bK8VXf/8P9lDc2hlXIbNGT g2oPkZ63crR3cODJhXvwgkxHnesvS1pK6MEKIEZfSBcD6t38V8hcU2Ylk3mSPfvf jwEzPYKvw3+2wmVVRlHTX7pV3SQv1flsCaIsGeqofPSFRNauPiabyZh50hw2zQZ1 QL3U5cb9bGu1rBmPlb2pesFoi8qc+z13D7efk7lqf0sLKJtMSGrZTPAho2Gv5LjR rsBWrvpKvr/ElT5yaNbuPifCm97vMa6+6glzqgg4fGzwj5V98QtgfNUjvV7OuK2W 1kC8RzQjh94PvdLUt9fvpPWpAK3R3vySW/myd2zFbNAfsBFEA8NGdmfccH/iEpc= =AYbT -----END PGP SIGNATURE----- --khWept0TPVbRObsv8Sk4csecodFnJHSpa-- From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 11 11:47:01 2014 Received: (at 18449) by debbugs.gnu.org; 11 Sep 2014 15:47:01 +0000 Received: from localhost ([127.0.0.1]:38264 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS6aK-0000vS-RG for submit@debbugs.gnu.org; Thu, 11 Sep 2014 11:47:01 -0400 Received: from ypig.lip.ens-lyon.fr ([140.77.13.48]:52440) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS6aH-0000vG-Ri for 18449@debbugs.gnu.org; Thu, 11 Sep 2014 11:46:58 -0400 Received: from vlefevre by ypig.lip.ens-lyon.fr with local (Exim 4.84) (envelope-from ) id 1XS6aG-0004r8-3l; Thu, 11 Sep 2014 17:46:56 +0200 Date: Thu, 11 Sep 2014 17:46:56 +0200 From: Vincent Lefevre To: =?iso-8859-1?Q?P=E1draig?= Brady Subject: Re: bug#18449: "cat x >> x" error even when x is empty Message-ID: <20140911154656.GA16547@ypig.lip.ens-lyon.fr> References: <20140911130044.GB4859@ypig.lip.ens-lyon.fr> <5411A186.8030408@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5411A186.8030408@draigBrady.com> X-Mailer-Info: http://www.vinc17.net/mutt/ User-Agent: Mutt/1.5.23-6361-vl-r59709 (2014-07-25) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18449 Cc: 18449@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: 0.0 (/) On 2014-09-11 14:20:06 +0100, Pádraig Brady wrote: > On 09/11/2014 02:00 PM, Vincent Lefevre wrote: > > This may not seem really useful here, but this can potentially break > > scripts with things like: > > > > cat "$foo" >> "$bar" > > > > where "$foo" may be the same file as "$bar" only if it is empty. > > I'm struggling to see that use case TBH. Seriously, I don't know whether this could occur in practice, but if it does, I wouldn't be surprised. If this may be regarded as an error, it is important that this is specified; the issue raised by Eric for the Austin Group may makes this clear. Let's just hope that users won't forget this particular case. As a comparison, one may think that in C, a shift like 0 << n, where n >= int width, would never occur in practice, but it did in one of my codes (I made sure that there was no integer overflow but forgot the constraint on the shift count, which adds a restriction only when the first argument is 0). -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon) From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 11 11:48:52 2014 Received: (at 18449) by debbugs.gnu.org; 11 Sep 2014 15:48:52 +0000 Received: from localhost ([127.0.0.1]:38267 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS6c7-0000ye-0c for submit@debbugs.gnu.org; Thu, 11 Sep 2014 11:48:51 -0400 Received: from nm25-vm1.bullet.mail.bf1.yahoo.com ([98.139.212.155]:46760) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS4TT-0005ZI-Nl for 18449@debbugs.gnu.org; Thu, 11 Sep 2014 09:31:48 -0400 Received: from [66.196.81.170] by nm25.bullet.mail.bf1.yahoo.com with NNFMP; 11 Sep 2014 13:31:47 -0000 Received: from [98.139.212.235] by tm16.bullet.mail.bf1.yahoo.com with NNFMP; 11 Sep 2014 13:31:47 -0000 Received: from [127.0.0.1] by omp1044.mail.bf1.yahoo.com with NNFMP; 11 Sep 2014 13:31:47 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 63871.4284.bm@omp1044.mail.bf1.yahoo.com Received: (qmail 31502 invoked by uid 60001); 11 Sep 2014 13:31:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1410442307; bh=LTN/wEM1bTHu5Qfrewv7LJTGmftpZr8cuR9N14k81HI=; h=References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=mjeyrZZzc5NMGJr4H4SWom44EmDaOTaoUGfsGXmJmDmHcFlY6QCKpBZDoWK+grbUkcPrH93wuXeUdMXG/+rkk1UhGutPyhwyIXX4yOVxlHjz8kJtwpYbda2DxQJdyEYtAaImNryUTdidxApcGb4c+aMC/GhW6fpWqNAMgBDKu0U= X-YMail-OSG: xhUdd8gVM1kbqNeDRBqPHfHU5TffiCwIFvgMNRI1kI115rd oe2qL.x7ZCsCuFGS09A9U2UxKWyIj05TuwKtY99oEiDULsk6k6FRBqmBYSBA kbrbyq6z.THprSyQ6_95Y_HZSxM76Fwf5F7jYzExPcgm8_84jbOUbLWZmuK3 xDGLViw7BDGYrKCY8H32t5sG2VvaET91LJPVmv3qJ6KIMz0gdg1rVNdrHqUR vwP6XHRM3Z1WHI8K3OnRmhY9eiAdntzg.oCD7gZMto_qswELdCbl_FJRdMK0 N7trR23_6DHGX7e74R3WSgPa76RTn9SbPUVuVc_oLYlGX.Bv4AJuuDRttQKR ev3oVQ94ZgNZmVpvCwsNOL2caPIlk9D0lO4CAC3GnKPSWRYwxUrelXtkLyRO WEiaZT4RLvydnEvij.i9qYoFqellWjguFS9d4sTkQSqBZu6mGO1djOEniNrp vcWSTRapGVVDlg5Lom.0HUc7zolSPjQnb4w7tD.32M4N4powWS8PFgWEoDX1 ykjViDr51Ah8Cyd3JmbCKUim1infkPwzMzZWT.DOuLNtD.vPqmDMplIM5lq9 CQslXOd6t Received: from [70.27.253.115] by web142602.mail.bf1.yahoo.com via HTTP; Thu, 11 Sep 2014 06:31:46 PDT X-Rocket-MIMEInfo: 002.001, V2l0aCBteSBGZWRvcmEgdmVyc2lvbiwgICB0aGVyZSBpcyBhbiBlcnJvciBtZXNzYWdlICAgKGlucHV0IGZpbGUgaXMgb3V0cHV0IGZpbGUpCgogY2F0IHggPngKY2F0OiB4OiBpbnB1dCBmaWxlIGlzIG91dHB1dCBmaWxlCgoKIApSZWdhcmRzIAoKIExlc2xpZQoKCgoKCj5fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwo.IEZyb206IFDDoWRyYWlnIEJyYWR5IDxQQGRyYWlnQnJhZHkuY29tPgo.VG86IFZpbmNlbnQgTGVmZXZyZSA8dmluY2VudEB2aW5jMTcubmV0PjsgMTg0NDlAZGViYnVncy5nbnUBMAEBAQE- X-Mailer: YahooMailWebService/0.8.203.696 References: <20140911130044.GB4859@ypig.lip.ens-lyon.fr> <5411A186.8030408@draigBrady.com> Message-ID: <1410442306.96226.YahooMailNeo@web142602.mail.bf1.yahoo.com> Date: Thu, 11 Sep 2014 06:31:46 -0700 From: Leslie S Satenstein Subject: Re: bug#18449: "cat x >> x" error even when x is empty To: =?iso-8859-1?Q?P=E1draig_Brady?= , Vincent Lefevre , "18449@debbugs.gnu.org" <18449@debbugs.gnu.org> In-Reply-To: <5411A186.8030408@draigBrady.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-1585520525-1977151766-1410442306=:96226" X-Spam-Score: -2.5 (--) X-Debbugs-Envelope-To: 18449 X-Mailman-Approved-At: Thu, 11 Sep 2014 11:48:48 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Leslie S Satenstein 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.5 (--) ---1585520525-1977151766-1410442306=:96226 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable With my Fedora version, there is an error message (input file is output= file)=0A=0A cat x >x=0Acat: x: input file is output file=0A=0A=0A =0ARegar= ds =0A=0A Leslie=0A=0A=0A=0A=0A=0A>________________________________=0A> Fro= m: P=E1draig Brady =0A>To: Vincent Lefevre ; 18449@debbugs.gnu.org =0A>Sent: Thursday, September 11, 2014 9:20 A= M=0A>Subject: bug#18449: "cat x >> x" error even when x is empty=0A> =0A>= =0A>On 09/11/2014 02:00 PM, Vincent Lefevre wrote:=0A>> With coreutils 8.23= under Debian/unstable:=0A>> =0A>> ypig% : > x=0A>> ypig% cat x >> x=0A>> c= at: x: input file is output file=0A>> ypig% POSIXLY_CORRECT=3D1 cat x >> x= =0A>> cat: x: input file is output file=0A>> =0A>> while there's no reason = to return an error in this case: the file=0A>> should just remain empty. Us= ing the same file for input and output=0A>> isn't disallowed by POSIX, AFAI= K.=0A>> =0A>> This may not seem really useful here, but this can potentiall= y break=0A>> scripts with things like:=0A>> =0A>> cat "$foo" >> "$bar"=0A= >> =0A>> where "$foo" may be the same file as "$bar" only if it is empty.= =0A>=0A>I'm struggling to see that use case TBH.=0A>=0A>=0A>> BTW, when x i= sn't empty, I wonder whether an error is correct if=0A>> POSIXLY_CORRECT is= set. The result will typically depend on the=0A>> implementation and possi= bly be non-deterministic, but POSIX doesn't=0A>> seem to allow an error (ex= cept FS errors, such as disk full).=0A>=0A>This is just a protection agains= t non deterministic usage.=0A>I.E. if there is data in the file then it'll = probably run=0A>until the file system is exhausted. This is what happens= =0A>on FreeBSD BTW, though I see that Solaris has the same=0A>protections a= s GNU.=0A>=0A>I wouldn't be on for removing this protection which=0A>has ex= isted from the initial GNU implementation.=0A>=0A>cheers,=0A>P=E1draig.=0A>= =0A>=0A>=0A>=0A>=0A>=0A> ---1585520525-1977151766-1410442306=:96226 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
With my= Fedora version,   there is an error message   (input f= ile is output file)

 cat x >x
cat: x: input file is = output file

 
Regards
=
 Leslie=

<= /font>
<= /div>


<= span class=3D"" style=3D"font-weight:bold;">From: P=E1draig Brad= y <P@draigBrady.com>
To: Vincent Lef= evre <vincent@vinc17.net>; 18449@debbugs.gnu.org
Sent: Thursday, September 11, 2014 9:20 AM
Subject: bug#18449: "cat x >> x" error even when x is empty

On 09/11/2014 02:00 PM, Vincent Lefevre= wrote:
> With coreutils 8.23 un= der Debian/unstable:
>
> ypig% : > x
> ypig% cat x >> x
> cat: x: input file is output file
> ypig% POSIXLY_CORRECT=3D1 cat x >> x
> cat: x: input file is output file
>
> while there's no reason to return an error in this case: the file> should just remain empty. Using= the same file for input and output
> isn't disallowed by POSIX, AFAIK.
>
> This may= not seem really useful here, but this can potentially break
> scripts with things like:
>
>&nb= sp; cat "$foo" >> "$bar"
>= ;
> where "$foo" may be the sam= e file as "$bar" only if it is empty.

I'm struggling to see that use = case TBH.


> BTW, whe= n x isn't empty, I wonder whether an error is correct if
> POSIXLY_CORRECT is set. The result will typicall= y depend on the
> implementation= and possibly be non-deterministic, but POSIX doesn't
> seem to allow an error (except FS errors, such as disk= full).


This is just a protection against non deterministic us= age.
I.E. if there is data in the f= ile then it'll probably run
until t= he file system is exhausted.  This is what happens
on FreeBSD BTW, though I see that Solaris has the same=
protections as GNU.

I wouldn= 't be on for removing this protection which
has existed from the initial GNU implementation.

cheers,P=E1draig.






---1585520525-1977151766-1410442306=:96226-- From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 11 11:52:28 2014 Received: (at 18449-done) by debbugs.gnu.org; 11 Sep 2014 15:52:28 +0000 Received: from localhost ([127.0.0.1]:38271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS6fb-00014w-H0 for submit@debbugs.gnu.org; Thu, 11 Sep 2014 11:52:28 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:42926) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XS6fY-00014l-4O for 18449-done@debbugs.gnu.org; Thu, 11 Sep 2014 11:52:25 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 366D2A6001B; Thu, 11 Sep 2014 08:52:21 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nkM917R5tZtO; Thu, 11 Sep 2014 08:52:17 -0700 (PDT) Received: from [192.168.1.9] (pool-71-177-17-123.lsanca.dsl-w.verizon.net [71.177.17.123]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 491B0A6001A; Thu, 11 Sep 2014 08:52:17 -0700 (PDT) Message-ID: <5411C531.60305@cs.ucla.edu> Date: Thu, 11 Sep 2014 08:52:17 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Eric Blake , =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= , Vincent Lefevre , 18449-done@debbugs.gnu.org Subject: Re: bug#18449: "cat x >> x" error even when x is empty References: <20140911130044.GB4859@ypig.lip.ens-lyon.fr> <5411A186.8030408@draigBrady.com> <5411B80A.4040707@redhat.com> In-Reply-To: <5411B80A.4040707@redhat.com> Content-Type: multipart/mixed; boundary="------------010009090502080108080302" X-Spam-Score: -4.8 (----) X-Debbugs-Envelope-To: 18449-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -4.8 (----) This is a multi-part message in MIME format. --------------010009090502080108080302 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Eric Blake wrote: > Testing for an empty file is enough of an additional special case over > the existing check for same files that I don't think it is worth it. It's a really cheap check, as a system call is needed only when the input and output files are the same, and even then it's only an lseek with SEEK_CUR so it's all in-memory. Plus, the POSIX 'cat' spec gives an example of using 'cat' to copy an empty regular file to itself, and (not unreasonably) says that should work. As far as POSIX conformance goes, I don't think we need to worry about POSIXLY_CORRECT here. We'll get POSIX fixed instead. Eric has already started the ball rolling on that (thanks). Though the POSIX fix should involve updating its example -- and quite possibly POSIX should continue to allow catting an empty file to itself. I installed the attached patch and am marking this as done. The 'cat' source code is simpler now, so that's a win anyway.... --------------010009090502080108080302 Content-Type: text/plain; charset=UTF-8; name="0001-cat-allow-copying-empty-files-to-themselves.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="0001-cat-allow-copying-empty-files-to-themselves.patch" RnJvbSBmYzYyMTU5ZTdmYjE0ZjA4NWY2N2YwMmIzZjk4YWY5ZTFlNjIzYTM3IE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBQYXVsIEVnZ2VydCA8ZWdnZXJ0QGNzLnVjbGEuZWR1 PgpEYXRlOiBUaHUsIDExIFNlcCAyMDE0IDA4OjQ1OjMyIC0wNzAwClN1YmplY3Q6IFtQQVRD SF0gY2F0OiBhbGxvdyBjb3B5aW5nIGVtcHR5IGZpbGVzIHRvIHRoZW1zZWx2ZXMKClByb2Js ZW0gcmVwb3J0ZWQgYnkgVmluY2VudCBMZWZldnJlIGluOiBodHRwOi8vYnVncy5nbnUub3Jn LzE4NDQ5Ciogc3JjL2NhdC5jIChtYWluKTogQWxsb3cgY29weWluZyBhbiBlbXB0eSBmaWxl IHRvIGl0c2VsZi4KKiB0ZXN0cy9taXNjL2NhdC1zZWxmLnNoOiBOZXcgdGVzdC4KKiB0ZXN0 cy9sb2NhbC5tayAoYWxsX3Rlc3RzKTogQWRkIGl0LgotLS0KIHNyYy9jYXQuYyAgICAgICAg ICAgICAgfCAzNyArKysrKysrKysrLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCiB0ZXN0 cy9sb2NhbC5tayAgICAgICAgIHwgIDEgKwogdGVzdHMvbWlzYy9jYXQtc2VsZi5zaCB8IDMz ICsrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKwogMyBmaWxlcyBjaGFuZ2VkLCA0 NCBpbnNlcnRpb25zKCspLCAyNyBkZWxldGlvbnMoLSkKIGNyZWF0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bD0xCisKK0V4aXQgJGZhaWwKLS0gCjEuOS4zCgo= --------------010009090502080108080302-- From unknown Thu Jun 19 16:19:35 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 10 Oct 2014 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator