From unknown Fri Aug 15 15:31:43 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#32703 <32703@debbugs.gnu.org> To: bug#32703 <32703@debbugs.gnu.org> Subject: Status: echo_man_error Reply-To: bug#32703 <32703@debbugs.gnu.org> Date: Fri, 15 Aug 2025 22:31:43 +0000 retitle 32703 echo_man_error reassign 32703 coreutils submitter 32703 "1064240043" severity 32703 normal tag 32703 moreinfo thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 11 11:18:45 2018 Received: (at submit) by debbugs.gnu.org; 11 Sep 2018 15:18:45 +0000 Received: from localhost ([127.0.0.1]:37227 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzkRB-0004YM-Du for submit@debbugs.gnu.org; Tue, 11 Sep 2018 11:18:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40340) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzgv1-0006lG-FZ for submit@debbugs.gnu.org; Tue, 11 Sep 2018 07:33:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzguv-0003IQ-IY for submit@debbugs.gnu.org; Tue, 11 Sep 2018 07:33:14 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_40, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_EXCESS_BASE64,HTML_MESSAGE, MSGID_FROM_MTA_HEADER,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:56181) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzguv-0003IK-EP for submit@debbugs.gnu.org; Tue, 11 Sep 2018 07:33:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzguu-00056Q-MO for bug-coreutils@gnu.org; Tue, 11 Sep 2018 07:33:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzguq-0003HM-BD for bug-coreutils@gnu.org; Tue, 11 Sep 2018 07:33:12 -0400 Received: from smtpbgau1.qq.com ([54.206.16.166]:55419) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzgup-0003FF-Do for bug-coreutils@gnu.org; Tue, 11 Sep 2018 07:33:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1536665575; bh=RzorI/Ffr/l5Y4q4Rto6vVNhHiJgP1GmKZ+j16bsTIc=; h=From:To:Subject:Mime-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID; b=l5u+BOpFjO2hbv2SPTA20giYjZjVdm19FDtzxnpFppxahev1IjsoXkywSIxBkHGuM kZ0YZ4Ucm9Yxv/kMLGox18XoRqQMHYTt8peUndiSMKzganKQ6ep76R4yjyDUu+tEoN 126WtoYKUU1TcU8QKjXsXmFJnNvWkf8jTBEMdTCM= X-QQ-FEAT: HkhB1cVcej/d8aCgCTjDE8byU+56JNTGMQ5fe5RyqVBD3qTTUkl8Q4ktqAj6q tdbov4UOwIS/MgbJAw7LB0NJI3n54UTouWYZuTe+q7RhBNZngc3FcgjZo8iXv8a8aEioaIZ jmleesi5+CSvr3RtRAZws6RrZOW8IGpVI8wWoYUz+fXEZx51efmDfciDNvIpfl9RMslIJIR hOTj9zf4e6110zSuKQlUboULOOE5O1XSg8pKwPIUSzJgosweBCp3EwXKlCRAL3IQsv69W+f NsqJzNrbPJaXe7v0ykqKr0ze4= X-QQ-SSF: 00000000000000F000000000000000Z X-HAS-ATTACH: no X-QQ-BUSINESS-ORIGIN: 2 X-Originating-IP: 113.54.210.132 X-QQ-STYLE: X-QQ-mid: webmail48t1536665574t7093349 From: "=?ISO-8859-1?B?MTA2NDI0MDA0Mw==?=" To: "=?ISO-8859-1?B?YnVnLWNvcmV1dGlscw==?=" Subject: echo_man_error Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_5B97A7E6_0BFF19B0_55F17644" Content-Transfer-Encoding: 8Bit Date: Tue, 11 Sep 2018 19:32:54 +0800 X-Priority: 3 Message-ID: X-QQ-MIME: TCMime 1.0 by Tencent X-Mailer: QQMail 2.x X-QQ-Mailer: QQMail 2.x X-QQ-SENDSIZE: 520 Received: from qq.com (unknown [127.0.0.1]) by smtp.qq.com (ESMTP) with SMTP id ; Tue, 11 Sep 2018 19:32:55 +0800 (CST) Feedback-ID: webmail:qq.com:bgforeign:bgforeign2 X-QQ-Bgrelay: 1 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: -3.7 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 11 Sep 2018 11:18:43 -0400 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: -4.7 (----) This is a multi-part message in MIME format. ------=_NextPart_5B97A7E6_0BFF19B0_55F17644 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: base64 SW4gTWFudWFsIHBhZ2UgZWNobygxKQ0KDQoNCml0IHNheXMgJy1FIGRpc2FibGUgaW50ZXJw cmV0YXRpb24gb2YgYmFja3NsYXNoIGVzY2FwZXMgKGRlZmF1bHQpJw0KDQoNCmJ1dCBJIHRy aWVkIGFuZCBmb3VuZCBvdXQgdGhhdCBlbmFibGUoLWUpIGlzIGRlZmF1bHQu ------=_NextPart_5B97A7E6_0BFF19B0_55F17644 Content-Type: text/html; charset="ISO-8859-1" Content-Transfer-Encoding: base64 PGRpdj5JbiBNYW51YWwgcGFnZSBlY2hvKDEpPC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5p dCBzYXlzICc8Yj4tRTwvYj4gZGlzYWJsZSBpbnRlcnByZXRhdGlvbiBvZiBiYWNrc2xhc2gg ZXNjYXBlcyAoPGI+ZGVmYXVsdDwvYj4pJzwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+YnV0 IEkgdHJpZWQgYW5kIGZvdW5kIG91dCB0aGF0PGI+IGVuYWJsZSgtZSkgaXMgZGVmYXVsdDwv Yj4uPC9kaXY+ ------=_NextPart_5B97A7E6_0BFF19B0_55F17644-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 11 12:02:08 2018 Received: (at 32703) by debbugs.gnu.org; 11 Sep 2018 16:02:08 +0000 Received: from localhost ([127.0.0.1]:37279 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzl7A-0005hi-2G for submit@debbugs.gnu.org; Tue, 11 Sep 2018 12:02:08 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40472 helo=mx1.redhat.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzl78-0005h8-6j; Tue, 11 Sep 2018 12:02:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87FB24075C4E; Tue, 11 Sep 2018 16:02:00 +0000 (UTC) Received: from [10.10.122.46] (ovpn-122-46.rdu2.redhat.com [10.10.122.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id E040D10DCF41; Tue, 11 Sep 2018 16:01:59 +0000 (UTC) Subject: Re: bug#32703: echo_man_error To: 1064240043 , 32703@debbugs.gnu.org References: From: Eric Blake Organization: Red Hat, Inc. Message-ID: Date: Tue, 11 Sep 2018 11:01:59 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.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.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 11 Sep 2018 16:02:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 11 Sep 2018 16:02:00 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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: 32703 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: -3.3 (---) tag 32703 needinfo thanks On 9/11/18 6:32 AM, 1064240043 wrote: > In Manual page echo(1) > > > it says '-E disable interpretation of backslash escapes (default)' > > > but I tried and found out that enable(-e) is default. What exactly did you try? And are you sure you are testing the same echo in your various tests? Remember that many shells ship echo as a built-in (both bash and dash, which are the two most common choices for /bin/sh on a GNU/Linux installation), so you have to first determine whether you are testing the behavior of your shell instead of the echo built as part of coreutils (which is often installed at /bin/echo). By the way, POSIX requires echo to behave with backslash escapes enabled by default (dash does this, and bash can be convinced to do it via 'set -o posix && shopt -s xpg_echo'). But oddly enough, coreutils does NOT quite seem to obey POSIX, even under POSIXLY_CORRECT. Note: $ /bin/echo --version | head -n1 echo (GNU coreutils) 8.29 $ POSIXLY_CORRECT=1 /bin/echo --version --version (so far, so good - printing --help/--version is a useful GNU extension, but violates POSIX, so we turn it off under POSIXLY_CORRECT) $ bash -c 'echo a\\nb' a\nb $ bash -c 'set -o posix; shopt -s xpg_echo; echo a\\nb' a b $ dash -c 'echo a\\nb' a b (okay, we've demonstrated that bash defaults to non-POSIX behavior, but that it can be coerced into obeying; and dash defaults to POSIX behavior) $ /bin/echo a\\nb a\nb (so far, so good - we've chosen to NOT expand backslash by default, which matches bash's defaults even if it violates POSIX) $ POSIXLY_CORRECT=1 /bin/echo a\\nb a\nb Yikes! Even though we asked for POSIX correctness, we are NOT interpreting backslashes. I think this is a bug in GNU coreutils' echo, and could be fixed by the patch below (but the testsuite would also need updates). But also note that POSIX has some rather wonky wording - it permits -n to have implementation-defined behavior, but forgot to give special exceptions to -e or -E. In short, the POSIX recommendation is that you NEVER use 'echo' if you are trying to print a string that might start with '-' or contain '\' - use printf instead. diff --git i/src/echo.c w/src/echo.c index 9958a8ec6..b3dfdb54a 100644 --- i/src/echo.c +++ w/src/echo.c @@ -189,7 +189,7 @@ main (int argc, char **argv) just_echo: - if (do_v9) + if (do_v9 || getenv ("POSIXLY_CORRECT")) { while (argc > 0) { -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 11 14:07:16 2018 Received: (at 32703) by debbugs.gnu.org; 11 Sep 2018 18:07:16 +0000 Received: from localhost ([127.0.0.1]:37340 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzn4F-0002P4-Pt for submit@debbugs.gnu.org; Tue, 11 Sep 2018 14:07:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43488 helo=mx1.redhat.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzn4D-0002Oo-Do for 32703@debbugs.gnu.org; Tue, 11 Sep 2018 14:07:13 -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 28A1187A50; Tue, 11 Sep 2018 18:07:08 +0000 (UTC) Received: from [10.10.122.46] (ovpn-122-46.rdu2.redhat.com [10.10.122.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CA1BD93DF; Tue, 11 Sep 2018 18:07:07 +0000 (UTC) Subject: Re: bug#32703: echo_man_error To: 1064240043 , 32703@debbugs.gnu.org References: From: Eric Blake Organization: Red Hat, Inc. Message-ID: <93d09523-8341-64a9-c819-02014b220331@redhat.com> Date: Tue, 11 Sep 2018 13:07:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit 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]); Tue, 11 Sep 2018 18:07:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 11 Sep 2018 18:07:08 +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: 32703 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: -3.3 (---) On 9/11/18 11:01 AM, Eric Blake wrote: > $ POSIXLY_CORRECT=1 /bin/echo a\\nb > a\nb > > Yikes!  Even though we asked for POSIX correctness, we are NOT > interpreting backslashes.  I think this is a bug in GNU coreutils' echo, > and could be fixed by the patch below (but the testsuite would also need > updates). And it might even be a regression. Reading through NEWS, I found this back in 5.3.0: echo now conforms to POSIX better. It supports the \0ooo syntax for octal escapes, and \c now terminates printing immediately. If POSIXLY_CORRECT is set and the first argument is not "-n", echo now outputs all option-like arguments instead of treating them as options. although I haven't actually tested prior versions to see if behavior has changed over time. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 16 02:43:42 2018 Received: (at 32703) by debbugs.gnu.org; 16 Sep 2018 06:43:42 +0000 Received: from localhost ([127.0.0.1]:41897 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1QmU-0005MN-6x for submit@debbugs.gnu.org; Sun, 16 Sep 2018 02:43:42 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:47000) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1QmQ-0005MD-SW for 32703@debbugs.gnu.org; Sun, 16 Sep 2018 02:43:39 -0400 Received: from localhost.localdomain (unknown [76.21.115.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 1AA1B9F90; Sun, 16 Sep 2018 07:43:36 +0100 (IST) Subject: Re: bug#32703: echo_man_error To: Eric Blake , 1064240043 , 32703@debbugs.gnu.org References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <9401232c-35e6-8a6a-36d9-c115f1fa4bc7@draigBrady.com> Date: Sat, 15 Sep 2018 23:43:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <93d09523-8341-64a9-c819-02014b220331@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 32703 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: -1.0 (-) On 11/09/18 11:07, Eric Blake wrote: > On 9/11/18 11:01 AM, Eric Blake wrote: > >> $ POSIXLY_CORRECT=1 /bin/echo a\\nb >> a\nb >> >> Yikes! Even though we asked for POSIX correctness, we are NOT >> interpreting backslashes. I think this is a bug in GNU coreutils' echo, >> and could be fixed by the patch below (but the testsuite would also need >> updates). > > And it might even be a regression. Reading through NEWS, I found this > back in 5.3.0: > > echo now conforms to POSIX better. It supports the \0ooo syntax for > octal escapes, and \c now terminates printing immediately. If > POSIXLY_CORRECT is set and the first argument is not "-n", echo now > outputs all option-like arguments instead of treating them as options. > > although I haven't actually tested prior versions to see if behavior has > changed over time. I agree that we shouldn't be divergent here. POSIXLY_CORRECT should enable interpretation of escapes. I don't think it's a regression though. >From a quick review, default interpretation of escapes was only controllable at compile time, until -e allowed interpretation as of commit b7bfc2d2 (textutils-1.22). Author: Jim Meyering Date: Thu Sep 25 12:58:50 1997 +0000 Make echo conform to POSIX. By default, don't interpret backslash escape sequences. POSIX may have changed in the meantime, but POSIXLY_CORRECT was never used as a condition for enabling interpretation of escapes. cheers, Pádraig From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 16 10:42:33 2018 Received: (at 32703) by debbugs.gnu.org; 16 Sep 2018 14:42:33 +0000 Received: from localhost ([127.0.0.1]:42261 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1YFt-0002MU-Kl for submit@debbugs.gnu.org; Sun, 16 Sep 2018 10:42:33 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:43970) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1YFs-0002MI-1Y for 32703@debbugs.gnu.org; Sun, 16 Sep 2018 10:42:32 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2D6BD161170; Sun, 16 Sep 2018 07:42:26 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id AJEi4B-6clP2; Sun, 16 Sep 2018 07:42:19 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 68440161511; Sun, 16 Sep 2018 07:42:19 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id oE71ufmmRqL9; Sun, 16 Sep 2018 07:42:19 -0700 (PDT) Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 41159161170; Sun, 16 Sep 2018 07:42:19 -0700 (PDT) Subject: Re: bug#32703: echo_man_error To: =?UTF-8?Q?P=c3=a1draig_Brady?= , Eric Blake , 1064240043 , 32703@debbugs.gnu.org References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> <9401232c-35e6-8a6a-36d9-c115f1fa4bc7@draigBrady.com> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Sun, 16 Sep 2018 07:42:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <9401232c-35e6-8a6a-36d9-c115f1fa4bc7@draigBrady.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 32703 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: -3.3 (---) P=C3=A1draig Brady wrote: > Author: Jim Meyering > Date: Thu Sep 25 12:58:50 1997 +0000 > Make echo conform to POSIX. By default, don't > interpret backslash escape sequences. >=20 > POSIX may have changed in the meantime, but POSIXLY_CORRECT > was never used as a condition for enabling interpretation of escapes. POSIX certainly did change in the meantime. In 1997 it was POSIX.2 (1992)= ,=20 whereas the requirements we're talking about weren't added until POSIX-20= 01. So=20 the bug is that coreutils echo hasn't been upgraded to the new standard s= ince=20 2001 and nobody has reported this until now. From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 23 22:48:29 2018 Received: (at 32703-done) by debbugs.gnu.org; 24 Sep 2018 02:48:29 +0000 Received: from localhost ([127.0.0.1]:51232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4Gv6-0001bo-Dv for submit@debbugs.gnu.org; Sun, 23 Sep 2018 22:48:29 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:50020) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4Gv2-0001be-On for 32703-done@debbugs.gnu.org; Sun, 23 Sep 2018 22:48:18 -0400 Received: from localhost.localdomain (unknown [76.21.115.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id DDEADA8E7; Mon, 24 Sep 2018 03:48:14 +0100 (IST) Subject: Re: bug#32703: echo_man_error To: Eric Blake , 1064240043 , 32703-done@debbugs.gnu.org References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: Date: Sun, 23 Sep 2018 19:48:12 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <93d09523-8341-64a9-c819-02014b220331@redhat.com> Content-Type: multipart/mixed; boundary="------------7D120382A4B8B9887A372B77" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 32703-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: -1.0 (-) This is a multi-part message in MIME format. --------------7D120382A4B8B9887A372B77 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 11/09/18 11:07, Eric Blake wrote: > On 9/11/18 11:01 AM, Eric Blake wrote: > >> $ POSIXLY_CORRECT=1 /bin/echo a\\nb >> a\nb >> >> Yikes! Even though we asked for POSIX correctness, we are NOT >> interpreting backslashes. I think this is a bug in GNU coreutils' echo, >> and could be fixed by the patch below (but the testsuite would also need >> updates). I'll push the attached later. Interesting there were no echo tests until now. Marking this as done. cheers, Pádraig. --------------7D120382A4B8B9887A372B77 Content-Type: text/x-patch; name="echo-posix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="echo-posix.patch" >From b263599c2e24d0ed75884b931c555c4c9210559b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Sun, 23 Sep 2018 19:35:24 -0700 Subject: [PATCH] echo: always process escapes when POSIXLY_CORRECT is set * src/echo.c (main): Always enable backslash processing if POSIXLY_CORRECT is set. * tests/misc/echo.sh: Add (the first) test for the echo command. * tests/local.mk: Reference the new test. * tests/misc/printf.sh: Update a stale comment. * doc/coreutils.texi (echo invocation). Mention that POSIXLY_CORRECT now always enables backslash processing. * NEWS: Mention the change in behavior. Fixes https://bugs.gnu.org/32703 Issue identified by Eric Blake. --- NEWS | 6 +++++ doc/coreutils.texi | 2 +- src/echo.c | 5 ++-- tests/local.mk | 1 + tests/misc/echo.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/misc/printf.sh | 5 ++-- 6 files changed, 79 insertions(+), 6 deletions(-) create mode 100755 tests/misc/echo.sh diff --git a/NEWS b/NEWS index aa3b4f9..c826dc0 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,12 @@ GNU coreutils NEWS -*- outline -*- ** Bug fixes df no longer corrupts displayed multibyte characters on macOS. + [bug introduced with coreutils-8.18] + +** Changes in behavior + + echo now always processes backslash escapes when the POSIXLY_CORRECT + environment variable is set. * Noteworthy changes in release 8.30 (2018-07-01) [stable] diff --git a/doc/coreutils.texi b/doc/coreutils.texi index dc28996..c4f6473 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -12587,7 +12587,7 @@ If the @env{POSIXLY_CORRECT} environment variable is set, then when @command{echo}'s first argument is not @option{-n} it outputs option-like arguments instead of treating them as options. For example, @code{echo -ne hello} outputs @samp{-ne hello} instead of -plain @samp{hello}. +plain @samp{hello}. Also backslash escapes are always enabled. POSIX does not require support for any options, and says that the behavior of @command{echo} is implementation-defined if any diff --git a/src/echo.c b/src/echo.c index 9958a8e..2aee5ac 100644 --- a/src/echo.c +++ b/src/echo.c @@ -108,8 +108,9 @@ int main (int argc, char **argv) { bool display_return = true; + bool posixly_correct = getenv ("POSIXLY_CORRECT"); bool allow_options = - (! getenv ("POSIXLY_CORRECT") + (! posixly_correct || (! DEFAULT_ECHO_TO_XPG && 1 < argc && STREQ (argv[1], "-n"))); /* System V machines already have a /bin/sh with a v9 behavior. @@ -189,7 +190,7 @@ main (int argc, char **argv) just_echo: - if (do_v9) + if (do_v9 || posixly_correct) { while (argc > 0) { diff --git a/tests/local.mk b/tests/local.mk index 47c6b95..9b7cb74 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -237,6 +237,7 @@ all_tests = \ tests/fmt/base.pl \ tests/fmt/long-line.sh \ tests/fmt/goal-option.sh \ + tests/misc/echo.sh \ tests/misc/env.sh \ tests/misc/ptx.pl \ tests/misc/test.pl \ diff --git a/tests/misc/echo.sh b/tests/misc/echo.sh new file mode 100755 index 0000000..133b52a --- /dev/null +++ b/tests/misc/echo.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# basic tests for echo + +# Copyright (C) 2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +prog='env echo' + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ echo + + +# Verify the methods of specifying "Escape": +# Note 4 octal digits are allows (unlike printf which uses up to 3) +printf '%s\n' . . . . . | tr . '\033' > exp +$prog -n -e '\x1b\n\e\n\33\n\033\n\0033\n' > out || fail=1 +compare exp out || fail=1 + +# Incomplete hex escapes are output as is (unlike printf) +printf '\\x\n' > exp +$prog -n -e '\x\n' > out || fail=1 +compare exp out || fail=1 + +# Always output -- (unlike printf) +$prog -- 'foo' > out || fail=1 +$prog -n -e -- 'foo\n' >> out || fail=1 +cat <<\EOF > exp +-- foo +-- foo +EOF +compare exp out || fail=1 + +# Ensure \c stops processing +$prog -e 'foo\n\cbar' > out || fail=1 +printf 'foo\n' > exp +compare exp out || fail=1 + +# With POSIXLY_CORRECT: +# only -n as the first (separate) option enables option processing +# -E is ignored +# escapes are processed by default +POSIXLY_CORRECT=1 $prog -n -E 'foo\n' > out || fail=1 +POSIXLY_CORRECT=1 $prog -nE 'foo' >> out || fail=1 +POSIXLY_CORRECT=1 $prog -E -n 'foo' >> out || fail=1 +POSIXLY_CORRECT=1 $prog --version >> out || fail=1 +cat <<\EOF > exp +foo +-nE foo +-E -n foo +--version +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/printf.sh b/tests/misc/printf.sh index 8716c56..75f5d12 100755 --- a/tests/misc/printf.sh +++ b/tests/misc/printf.sh @@ -60,9 +60,8 @@ $prog '5 % +d\n' 234 >> out || fail=1 # coreutils-5.0.1, it would print six bytes: "6 \41\n". $prog '6 \41\n' | tr '\41' '!' >> out -# Note that as of coreutils-5.0.1, printf with a format of '\0002x' -# prints a NUL byte followed by the digit '2' and an 'x'. -# By contrast bash's printf outputs the same thing as $(printf '\2x') does. +# Note that as of coreutils-5.0.1, printf with a format of '\0002y' +# prints a NUL byte followed by the digit '2' and an 'y'. $prog '7 \2y \02y \002y \0002y\n' |tr '\0\2' '*=' >> out $prog '8 %b %b %b %b\n' '\1y' '\01y' '\001y' '\0001y'|tr '\1' = >> out -- 2.9.3 --------------7D120382A4B8B9887A372B77-- From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 24 09:52:53 2018 Received: (at 32703-done) by debbugs.gnu.org; 24 Sep 2018 13:52:53 +0000 Received: from localhost ([127.0.0.1]:51501 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4RID-0005ow-8q for submit@debbugs.gnu.org; Mon, 24 Sep 2018 09:52:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51712) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4RIB-0005oh-O1 for 32703-done@debbugs.gnu.org; Mon, 24 Sep 2018 09:52:52 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0B16308AA0E; Mon, 24 Sep 2018 13:52:45 +0000 (UTC) Received: from [10.10.125.13] (ovpn-125-13.rdu2.redhat.com [10.10.125.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0ED9E5F58B; Mon, 24 Sep 2018 13:52:44 +0000 (UTC) Subject: Re: bug#32703: echo_man_error To: =?UTF-8?Q?P=c3=a1draig_Brady?= , 1064240043 , 32703-done@debbugs.gnu.org References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> From: Eric Blake Organization: Red Hat, Inc. Message-ID: <4a52b003-0d89-4378-9c07-2f5848beaf03@redhat.com> Date: Mon, 24 Sep 2018 08:52:43 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 24 Sep 2018 13:52:45 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 32703-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: -6.0 (------) On 9/23/18 9:48 PM, Pádraig Brady wrote: > I'll push the attached later. > Interesting there were no echo tests until now. > > Marking this as done. Thanks. > +++ b/tests/misc/echo.sh > + > +# Verify the methods of specifying "Escape": > +# Note 4 octal digits are allows (unlike printf which uses up to 3) allowed > +++ b/tests/misc/printf.sh > @@ -60,9 +60,8 @@ $prog '5 % +d\n' 234 >> out || fail=1 > # coreutils-5.0.1, it would print six bytes: "6 \41\n". > $prog '6 \41\n' | tr '\41' '!' >> out > > -# Note that as of coreutils-5.0.1, printf with a format of '\0002x' > -# prints a NUL byte followed by the digit '2' and an 'x'. > -# By contrast bash's printf outputs the same thing as $(printf '\2x') does. > +# Note that as of coreutils-5.0.1, printf with a format of '\0002y' > +# prints a NUL byte followed by the digit '2' and an 'y'. s/an/a/ -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 24 17:47:57 2018 Received: (at 32703) by debbugs.gnu.org; 24 Sep 2018 21:47:58 +0000 Received: from localhost ([127.0.0.1]:52594 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4Yhv-00033c-18 for submit@debbugs.gnu.org; Mon, 24 Sep 2018 17:47:56 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:56703) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4Yhs-00033J-Kh for 32703@debbugs.gnu.org; Mon, 24 Sep 2018 17:47:53 -0400 Received: from [192.168.101.10] ([91.1.210.52]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mwfj2-1fpkbW1VMI-00yAiT; Mon, 24 Sep 2018 23:47:40 +0200 Subject: Re: bug#32703: echo_man_error To: 32703@debbugs.gnu.org, P@draigBrady.com, szq1064240043@qq.com References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> From: Bernhard Voelker Openpgp: preference=signencrypt Autocrypt: addr=mail@bernhard-voelker.de; prefer-encrypt=mutual; keydata= xsBNBFPirzMBCACyzYldTjQ4ufFOkByY5Nn5USb5GFoL48nWBwNHjd9KUbtRRNlQiPNKd6hK Gvd3BGi5aoFKA4ytfRk6jbAbW3jVb3R8wYaV08mOy4KVEKxqN4bxsXlMjNChXVR+rtKDmfI+ oPTL+cPH2X6gW4W02IRbVw0uUhNm6zEedC/gNrY/mTlf1enZ46jxZ7BTUZaG+kx38UMISIMB zSzLRtdkwgmHj4jS3p1fF2cwRqLclIfMjKGpbNFPEXeXKWrCLcqHw78795eAR9q0YvrDkfIn GdDBwfb3VM4NdulwIFzvYZMSXvSbbyPLB5YkHU5aAWQHUse4WlfT5ccDpbzUYldRAvF9ABEB AAHNK0Jlcm5oYXJkIFZvZWxrZXIgPG1haWxAYmVybmhhcmQtdm9lbGtlci5kZT7CwHkEEwEC ACMFAlPirzMCGwMHCwkIBwMCAQYVCAIJCgsEFgIDAQIeAQIXgAAKCRBGUC73lpFxle5wCACC dbs0QaJ0vR3Sff2cKdTk41rUq3YfWngsR///IOU0C5DdkePmCnJE/lUsUy0LRTxcUDLxQR+x QHU8ssRT0JUO9726dI3miy36UdsgmBYaOtLvQcidGmW1R7o0PYYf04+TFtyqKgngOUBPpMgR 6o4UsQxy/OD4bN1WDqOgIjL+D/qJpkKmgp6L6+hhaBCpiOFKRmmV7YyQ3SqVlfQNiHs5ZtkR nXpIjgZARV+GllKucI17bO0CGmTJZ1tstVy0+W3DQT1lbBkTTc++5LONM99D3jjn23l1ocOp folR53F7I4cb2RNfT23v1I59RH37lB9wMOqrKj0UjYAC2YoPGQ3BzsBNBFPirzMBCADXLWWp QihBldY6reca8ZKdc3T9qXEOa3akE3DWKztIBmNJhtYOjmpLYajQTkGa7UoJTnbmZE2Rn6ZE oNnvb0gcFNAIcY95KOI+bjOR8HEgh4cx2REXh6L6olIgyXqt/KFusE4wtVZAFxZl+30HzN6n D+1HvrjXxPJRX6MsIYOYyyX9/6OofwJK6QHODYGp8WL2olHDnmsXg4AT6Wlr7qKpKrQELlcF R4xkvdmgL/Ghw/tK0yJTxMIcewCCZWLPOXRmFRbvAadZWPAgVsJ63siNyUlVnVMSzDgTJl+s l/DMabXpqrJQx3/1Yy6mTaDs3XZT/wmBKaTLXx/LByaPxQQ7ABEBAAHCwF8EGAECAAkFAlPi rzMCGwwACgkQRlAu95aRcZWVPwgAqZT6iTXkoP37wYb41323RzhBcJ8JSk4cyBDBUXX0lMrM 3qhiClKG7phpxVdu817Gwc6Hsecg7FfjQAV8MHQ0ZFeEFdk3b2rKBqfsStc+h49/xF3Fb+if CzR9qeQF82fMSxkg18++7hMcHCMO/hPZ/Q0xRi+lrSr2QKDJQuLzSyVU14TxrCkevZjEhtma VNvcJlJzCbiBXee9Fpc5jITUXPFG8E8dxqo1n+duOyIMgozrAnzP7X5V/Ob/Ozf/aGGX9+Jd inyfCX18nWcHALKMU/36Eua/ylalf/2c2YkBp9KCLVmGgPkUgW52EeRPgroIsiwu+rwCSV6Z UyCJ+OymCg== Message-ID: <78180ded-16a3-8e55-4d9c-6a36cf2b2220@bernhard-voelker.de> Date: Mon, 24 Sep 2018 23:47:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------94BCCBCC6BE1AE10E3B22F84" Content-Language: en-US X-Provags-ID: V03:K1:yjLLHiQNhSZ2kRKG6rnK6bMskFfpaCqlfY9gSyrcODwGwH2+s2A Nzr/a7TsumtGIjF32WDmvureaINhwj35IYHv5Lw/5IGqERWK9RjnC/9PdpzJtAWw1GIfRBd gCwvD9im03uoHnN4fyDW5Kp3PwArXKYWImctzJmgB2gOnf316TS6w2DvnzyJARD9cvHNJih F3ISYXmSixxDO7jmu17Zw== X-UI-Out-Filterresults: notjunk:1;V01:K0:zBX3Mmg71kc=:3/t8EjtUdReQ4+rbdaDByg du8I3XXfTRPMak6pyChJKix477pC8qQK8Y3DJE3Dj8/8RwLQvF4Rkc/YSo0uc0U7WHVLGeVQj hoPfhfv+nt63l41NAVLsHiOTrdgeZvux8mtewjh3AqnPwh5773gDYZDbzVh7O4uYgkpS5PdHa k4JB7MiTdl+xwJZgV7DXbFrvzOOd8BF3iU5Mj8/q88d2tJ55Elm1/n6bx9lm7r9HhJmWOoRMq NmQMKJOG/G/MBvrAS+zMMbReDQt0iCjiiEJJyijwhgesYpEIJyEfz885msLLGJafs4eStcqts 4WjXlWCmHkBBzaId5bXxvnDiLszRZxI0Ja2/tEQ/oSyewy1Qnpj4fjTxj6AwdKm5G1IyocX2y DeE8YTANyoL7geUsbIh7Q8tbYhDMcRFmhkGsdZS2NCS8QplfVJI+cPNOI1mwIdaVA5pvVk3hH c0GOAB9Q7u6c6abJM7WEIocLsQuZc2kdSlKlOqxVDg84zbVkqxUSPCCsJG1yt04dxcoQT9fiE /X26WpV5x04u2TmyNLk8guRARhXX3i7lriC48NlZLBvTsztXwUY0n7rtUdxL91i40+xAa+Gss BtROk9XBzMvzV//X1mdtk+QwMR3rTZx4BwOAgjcY2oTV/xcPP/UqDir8WeNkSvwJg9YfXdu5z /rH89wQhMD1HYRQOyip9sNMgIbphuhNXbmrbhuPdSqHGWVEoYzNRAhVkjUMY4+09Xs3A= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 32703 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: -1.0 (-) This is a multi-part message in MIME format. --------------94BCCBCC6BE1AE10E3B22F84 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 9/24/18 4:48 AM, Pádraig Brady wrote: > I'll push the attached later. > Interesting there were no echo tests until now. Nice work, indeed. Additionally to Eric's comment, I'd suggest to increase the coverage for 'echo' to about 100% [1] with the attached patch: * src/echo.c (usage): Assert that STATUS is always EXIT_SUCCESS. * tests/misc/echo.sh: Add further tests for all hex and escape and escape characters. You may simply squash it in. [1] To get coverage statistic, run: make coverage -j 4 TESTS=tests/misc/echo.sh SUBDIRS=. xdg-open file:doc/coverage/src/echo.c.gcov.frameset.html Have a nice day, Berny --------------94BCCBCC6BE1AE10E3B22F84 Content-Type: text/x-patch; name="echo-test-coverage.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="echo-test-coverage.diff" diff --git a/src/echo.c b/src/echo.c index 2aee5acfb..062f9038c 100644 --- a/src/echo.c +++ b/src/echo.c @@ -16,6 +16,7 @@ =20 #include #include +#include #include #include "system.h" =20 @@ -34,35 +35,35 @@ enum { DEFAULT_ECHO_TO_XPG =3D false }; void usage (int status) { - if (status !=3D EXIT_SUCCESS) - emit_try_help (); - else - { - printf (_("\ + /* STATUS should always be EXIT_SUCCESS (unlike in most other + utilities which would call emit_try_help otherwise). */ + assert (status =3D=3D EXIT_SUCCESS); + + printf (_("\ Usage: %s [SHORT-OPTION]... [STRING]...\n\ or: %s LONG-OPTION\n\ "), program_name, program_name); - fputs (_("\ + fputs (_("\ Echo the STRING(s) to standard output.\n\ \n\ -n do not output the trailing newline\n\ "), stdout); - fputs (_(DEFAULT_ECHO_TO_XPG - ? N_("\ + fputs (_(DEFAULT_ECHO_TO_XPG + ? N_("\ -e enable interpretation of backslash escapes (default)\n\= -E disable interpretation of backslash escapes\n") - : N_("\ + : N_("\ -e enable interpretation of backslash escapes\n\ -E disable interpretation of backslash escapes (default)\n= ")), - stdout); - fputs (HELP_OPTION_DESCRIPTION, stdout); - fputs (VERSION_OPTION_DESCRIPTION, stdout); - fputs (_("\ + stdout); + fputs (HELP_OPTION_DESCRIPTION, stdout); + fputs (VERSION_OPTION_DESCRIPTION, stdout); + fputs (_("\ \n\ If -e is in effect, the following sequences are recognized:\n\ \n\ "), stdout); - fputs (_("\ + fputs (_("\ \\\\ backslash\n\ \\a alert (BEL)\n\ \\b backspace\n\ @@ -74,13 +75,12 @@ If -e is in effect, the following sequences are recog= nized:\n\ \\t horizontal tab\n\ \\v vertical tab\n\ "), stdout); - fputs (_("\ + fputs (_("\ \\0NNN byte with octal value NNN (1 to 3 digits)\n\ \\xHH byte with hexadecimal value HH (1 to 2 digits)\n\ "), stdout); - printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME); - emit_ancillary_info (PROGRAM_NAME); - } + printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME); + emit_ancillary_info (PROGRAM_NAME); exit (status); } =20 diff --git a/tests/misc/echo.sh b/tests/misc/echo.sh index 133b52a35..c3d67cf1b 100755 --- a/tests/misc/echo.sh +++ b/tests/misc/echo.sh @@ -63,4 +63,37 @@ foo EOF compare exp out || fail=3D1 =20 +# Further test coverage. +# Output a literal '-' (on a line itself). +$prog - > out || fail=3D1 +# Output a literal backslash '\', no newline. +$prog -n -e '\\' >> out || fail=3D1 +# Output an empty line (merely to have a newline after the previous test= ). +$prog >> out || fail=3D1 +# Test other characters escaped by a backslash: +# \a hex 07 alert, bell +# \b hex 08 backspace +# \e hex 1b escape +# \f hex 0c form feed +# \n hex 0a new line +# \r hex 0d carriage return +# \t hex 09 horizontal tab +# \v hex 0b vertical tab +# Convert output, yet checking the exit status of $prog. +{ $prog -n -e '\a\b\e\f\n\r\t\v' || touch fail; } | od -tx1 >> out || fa= il=3D1 +test '!' -f fail || fail=3D1 +# Output hex values which contain hexadecimal characters to test hextobi= n(). +# Hex values 4a through 4f are ASCII "JKLMNO". +$prog -n -e '\x4a\x4b\x4c\x4d\x4e\x4f\x4A\x4B\x4C\x4D\x4E\x4F' >> out ||= fail=3D1 +# Output another newline. +$prog >> out || fail=3D1 +cat <<\EOF > exp +- +\ +0000000 07 08 1b 0c 0a 0d 09 0b +0000010 +JKLMNOJKLMNO +EOF +compare exp out || fail=3D1 + Exit $fail --------------94BCCBCC6BE1AE10E3B22F84-- From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 24 18:16:11 2018 Received: (at 32703-done) by debbugs.gnu.org; 24 Sep 2018 22:16:11 +0000 Received: from localhost ([127.0.0.1]:52613 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4Z9G-0003oh-G5 for submit@debbugs.gnu.org; Mon, 24 Sep 2018 18:16:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51628) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4Z9A-0003nv-KE for 32703-done@debbugs.gnu.org; Mon, 24 Sep 2018 18:16:06 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97676CFFB; Mon, 24 Sep 2018 22:15:58 +0000 (UTC) Received: from [10.10.125.13] (ovpn-125-13.rdu2.redhat.com [10.10.125.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id E993EC0696; Mon, 24 Sep 2018 22:15:57 +0000 (UTC) Subject: Re: bug#32703: echo_man_error To: =?UTF-8?Q?P=c3=a1draig_Brady?= , 1064240043 , 32703-done@debbugs.gnu.org References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> From: Eric Blake Organization: Red Hat, Inc. Message-ID: Date: Mon, 24 Sep 2018 17:15:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 24 Sep 2018 22:15:58 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 32703-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: -6.0 (------) On 9/23/18 9:48 PM, Pádraig Brady wrote: > +++ b/NEWS > @@ -5,6 +5,12 @@ GNU coreutils NEWS -*- outline -*- > ** Bug fixes > > df no longer corrupts displayed multibyte characters on macOS. > + [bug introduced with coreutils-8.18] > + > +** Changes in behavior > + > + echo now always processes backslash escapes when the POSIXLY_CORRECT > + environment variable is set. Having re-read the POSIX wording, I'm not quite sure we are still accurate. > +++ b/src/echo.c > @@ -108,8 +108,9 @@ int > main (int argc, char **argv) > { > bool display_return = true; > + bool posixly_correct = getenv ("POSIXLY_CORRECT"); > bool allow_options = > - (! getenv ("POSIXLY_CORRECT") > + (! posixly_correct > || (! DEFAULT_ECHO_TO_XPG && 1 < argc && STREQ (argv[1], "-n"))); This special-cases a literal "-n" as the first argument, while POSIX states (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html) Implementations shall not support any options. A string to be written to standard output. If the first operand is -n, or if any of the operands contain a character, the results are implementation-defined. and then with XSI shading states: On XSI-conformant systems, if the first operand is -n, it shall be treated as a string, not an option. So my initial patch (which you took and improved) still isn't quite right. > + > +# With POSIXLY_CORRECT: > +# only -n as the first (separate) option enables option processing Rather, not even -n should get special treatment as an option. > +# -E is ignored > +# escapes are processed by default > +POSIXLY_CORRECT=1 $prog -n -E 'foo\n' > out || fail=1 So I would argue that this should output $'-n -E foo\n'. > +POSIXLY_CORRECT=1 $prog -nE 'foo' >> out || fail=1 > +POSIXLY_CORRECT=1 $prog -E -n 'foo' >> out || fail=1 > +POSIXLY_CORRECT=1 $prog --version >> out || fail=1 > +cat <<\EOF > exp > +foo > +-nE foo > +-E -n foo > +--version > +EOF > +compare exp out || fail=1 -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 25 00:10:59 2018 Received: (at 32703) by debbugs.gnu.org; 25 Sep 2018 04:10:59 +0000 Received: from localhost ([127.0.0.1]:52693 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4egd-0004Kh-CA for submit@debbugs.gnu.org; Tue, 25 Sep 2018 00:10:59 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:43410) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4egc-0004KZ-Hs for 32703@debbugs.gnu.org; Tue, 25 Sep 2018 00:10:58 -0400 Received: from localhost.localdomain (unknown [76.21.115.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id CF1C59916; Tue, 25 Sep 2018 05:10:56 +0100 (IST) Subject: Re: bug#32703: echo_man_error To: Bernhard Voelker , 32703@debbugs.gnu.org, szq1064240043@qq.com References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> <78180ded-16a3-8e55-4d9c-6a36cf2b2220@bernhard-voelker.de> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: Date: Mon, 24 Sep 2018 21:10:54 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <78180ded-16a3-8e55-4d9c-6a36cf2b2220@bernhard-voelker.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 32703 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: -1.0 (-) On 24/09/18 14:47, Bernhard Voelker wrote: > On 9/24/18 4:48 AM, Pádraig Brady wrote: >> I'll push the attached later. >> Interesting there were no echo tests until now. > > Nice work, indeed. > > Additionally to Eric's comment, I'd suggest to increase the coverage > for 'echo' to about 100% [1] with the attached patch: > > * src/echo.c (usage): Assert that STATUS is always EXIT_SUCCESS. > * tests/misc/echo.sh: Add further tests for all hex and escape and > escape characters. > > You may simply squash it in. > > [1] To get coverage statistic, run: > make coverage -j 4 TESTS=tests/misc/echo.sh SUBDIRS=. > xdg-open file:doc/coverage/src/echo.c.gcov.frameset.html > > > Have a nice day, > Berny > Excellent! I'll push this as its own patch. thanks! Pádraig From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 25 00:51:36 2018 Received: (at 32703-done) by debbugs.gnu.org; 25 Sep 2018 04:51:36 +0000 Received: from localhost ([127.0.0.1]:52722 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4fJv-0005QW-VV for submit@debbugs.gnu.org; Tue, 25 Sep 2018 00:51:36 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:43774) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4fJu-0005QO-9K for 32703-done@debbugs.gnu.org; Tue, 25 Sep 2018 00:51:34 -0400 Received: from localhost.localdomain (unknown [76.21.115.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 197179C49; Tue, 25 Sep 2018 05:51:32 +0100 (IST) Subject: Re: bug#32703: echo_man_error To: Eric Blake , 1064240043 , 32703-done@debbugs.gnu.org References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: Date: Mon, 24 Sep 2018 21:51:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 32703-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: -1.0 (-) On 24/09/18 15:15, Eric Blake wrote: > On 9/23/18 9:48 PM, Pádraig Brady wrote: > >> +++ b/NEWS >> @@ -5,6 +5,12 @@ GNU coreutils NEWS -*- outline -*- >> ** Bug fixes >> >> df no longer corrupts displayed multibyte characters on macOS. >> + [bug introduced with coreutils-8.18] >> + >> +** Changes in behavior >> + >> + echo now always processes backslash escapes when the POSIXLY_CORRECT >> + environment variable is set. > > Having re-read the POSIX wording, I'm not quite sure we are still accurate. > >> +++ b/src/echo.c >> @@ -108,8 +108,9 @@ int >> main (int argc, char **argv) >> { >> bool display_return = true; >> + bool posixly_correct = getenv ("POSIXLY_CORRECT"); >> bool allow_options = >> - (! getenv ("POSIXLY_CORRECT") >> + (! posixly_correct >> || (! DEFAULT_ECHO_TO_XPG && 1 < argc && STREQ (argv[1], "-n"))); > > This special-cases a literal "-n" as the first argument, while POSIX > states (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html) > > Implementations shall not support any options. > > A string to be written to standard output. If the first operand is -n, > or if any of the operands contain a character, the results > are implementation-defined. > > and then with XSI shading states: > > On XSI-conformant systems, if the first operand is -n, it shall be > treated as a string, not an option. > > So my initial patch (which you took and improved) still isn't quite right. I noticed that POSIX wording too, but erred on the side of consistency: $ bash -c 'set -o posix; shopt -s xpg_echo; echo -n foo' -n foo $ bash -c 'set -o posix; echo -n foo' foo $ dash -c 'echo -n foo' foo Now we do have compile time control over xpg mode so should probably restrict the no option processing to that mode? In summary the handling of -n specially is weird and inconsistent with bash, so in a separate patch I propose we handle all (leading) options also with POSIXLY_CORRECT to be consistent with bash. Oh hang on. It's the "xpg_echo" bash setting that enables -e by default :/ We don't have a runtime setting for that at present. $ bash -c 'set -o posix; echo -ne a\\nb\\n' a b bash -c 'set -o posix; echo -E a\\nb' a\nb $ bash -c 'set -o posix; shopt -s xpg_echo; echo a\\nb' a b $ bash -c 'set -o posix; echo a\\nb' a\nb $ bash -c 'set -o posix; echo -e a\\nb' a b So there is no way to be consistent with bash and dash I think. Let's have bash and coreutils consistent at least. The only question is whether POSIXLY_CORRECT in coreutils is equiv to `shopt -s xpg_echo` in bash or not. Assuming it is, then we'll need to echo -n when set as you say. Le sigh. What a mess cheers, Pádraig From unknown Fri Aug 15 15:31:43 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 23 Oct 2018 11:24:03 +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 From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 27 07:42:12 2018 Received: (at control) by debbugs.gnu.org; 27 Oct 2018 11:42:12 +0000 Received: from localhost ([127.0.0.1]:44666 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGMyp-0000JT-Qh for submit@debbugs.gnu.org; Sat, 27 Oct 2018 07:42:11 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:51992) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGMyn-0000JK-Gh for control@debbugs.gnu.org; Sat, 27 Oct 2018 07:42:09 -0400 Received: from localhost.localdomain (unknown [109.79.71.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 24652A3C9 for ; Sat, 27 Oct 2018 12:42:06 +0100 (IST) To: GNU bug tracker automated control server From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <55c90529-9174-9c3b-97e8-3177ad0fedca@draigBrady.com> Date: Sat, 27 Oct 2018 04:41:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: unarchive 32703 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject 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: 1.0 (+) unarchive 32703 From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 27 07:55:33 2018 Received: (at 32703) by debbugs.gnu.org; 27 Oct 2018 11:55:33 +0000 Received: from localhost ([127.0.0.1]:44678 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGNBl-0002fM-FC for submit@debbugs.gnu.org; Sat, 27 Oct 2018 07:55:33 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:52038) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGNBh-0002fB-MB for 32703@debbugs.gnu.org; Sat, 27 Oct 2018 07:55:30 -0400 Received: from localhost.localdomain (unknown [109.79.71.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 0540DA4F5 for <32703@debbugs.gnu.org>; Sat, 27 Oct 2018 12:55:28 +0100 (IST) Subject: Re: bug#32703: echo_man_error To: 32703@debbugs.gnu.org References: <93d09523-8341-64a9-c819-02014b220331@redhat.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: Date: Sat, 27 Oct 2018 04:55:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 32703 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: -1.0 (-) On 24/09/18 21:51, Pádraig Brady wrote: > On 24/09/18 15:15, Eric Blake wrote: >> On 9/23/18 9:48 PM, Pádraig Brady wrote: >> >>> +++ b/NEWS >>> @@ -5,6 +5,12 @@ GNU coreutils NEWS -*- outline -*- >>> ** Bug fixes >>> >>> df no longer corrupts displayed multibyte characters on macOS. >>> + [bug introduced with coreutils-8.18] >>> + >>> +** Changes in behavior >>> + >>> + echo now always processes backslash escapes when the POSIXLY_CORRECT >>> + environment variable is set. >> >> Having re-read the POSIX wording, I'm not quite sure we are still accurate. >> >>> +++ b/src/echo.c >>> @@ -108,8 +108,9 @@ int >>> main (int argc, char **argv) >>> { >>> bool display_return = true; >>> + bool posixly_correct = getenv ("POSIXLY_CORRECT"); >>> bool allow_options = >>> - (! getenv ("POSIXLY_CORRECT") >>> + (! posixly_correct >>> || (! DEFAULT_ECHO_TO_XPG && 1 < argc && STREQ (argv[1], "-n"))); >> >> This special-cases a literal "-n" as the first argument, while POSIX >> states (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html) >> >> Implementations shall not support any options. >> >> A string to be written to standard output. If the first operand is -n, >> or if any of the operands contain a character, the results >> are implementation-defined. >> >> and then with XSI shading states: >> >> On XSI-conformant systems, if the first operand is -n, it shall be >> treated as a string, not an option. >> >> So my initial patch (which you took and improved) still isn't quite right. > > I noticed that POSIX wording too, > but erred on the side of consistency: > > $ bash -c 'set -o posix; shopt -s xpg_echo; echo -n foo' > -n foo > > $ bash -c 'set -o posix; echo -n foo' > foo > $ dash -c 'echo -n foo' > foo > > Now we do have compile time control over xpg mode so > should probably restrict the no option processing > to that mode? > In summary the handling of -n specially is weird > and inconsistent with bash, so in a separate patch > I propose we handle all (leading) options also > with POSIXLY_CORRECT to be consistent with bash. > > Oh hang on. It's the "xpg_echo" bash setting that enables -e by default :/ > We don't have a runtime setting for that at present. > > $ bash -c 'set -o posix; echo -ne a\\nb\\n' > a > b > bash -c 'set -o posix; echo -E a\\nb' > a\nb > > $ bash -c 'set -o posix; shopt -s xpg_echo; echo a\\nb' > a > b > $ bash -c 'set -o posix; echo a\\nb' > a\nb > $ bash -c 'set -o posix; echo -e a\\nb' > a > b > > So there is no way to be consistent with bash and dash I think. > Let's have bash and coreutils consistent at least. > The only question is whether POSIXLY_CORRECT in coreutils > is equiv to `shopt -s xpg_echo` in bash or not. > Assuming it is, then we'll need to echo -n when set as you say. > > Le sigh. What a mess Thinking a bit more about this, basically for -e, in echo(1), bash, and dash, where -e is not interpreted as an option we should interpret backslashes by default. That's what this patch now does. For -n, dash and bash (set -o posix), do give the facility to outputting without the trailing newline by interpreting the -n option, and POSIX says this is implementation defined, so let's continue to provide this facility. We've compile time support for the less frequently needed facility to output a leading -n, dash doesn't currently have this facility. bash supports this with `shopt -s xpg_echo`. I suggest we don't change this with POSIXLY_CORRECT, or if we do with a subsequent patch, to do do it with a separate env var/value. Pushing these two patches now... cheers, Pádraig From unknown Fri Aug 15 15:31:43 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 24 Nov 2018 12: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