GNU bug report logs - #14115
[PATCH] echo: adding support for '--' in option parsing

Previous Next

Package: coreutils;

Reported by: Hemmo Nieminen <hemmo.nieminen <at> iki.fi>

Date: Mon, 1 Apr 2013 15:18:01 UTC

Severity: normal

Tags: notabug, patch, wontfix

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14115 in the body.
You can then email your comments to 14115 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#14115; Package coreutils. (Mon, 01 Apr 2013 15:18:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Hemmo Nieminen <hemmo.nieminen <at> iki.fi>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 01 Apr 2013 15:18:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Hemmo Nieminen <hemmo.nieminen <at> iki.fi>
To: bug-coreutils <at> gnu.org
Cc: Hemmo Nieminen <hemmo.nieminen <at> iki.fi>
Subject: [PATCH] echo: adding support for '--' in option parsing
Date: Mon,  1 Apr 2013 12:49:52 +0300
A '--' can now be used to mark the end of echo's options that should be
parsed. This makes it possible to e.g. print lines where the first
argument matches some of echo's options (e.g. 'echo -- -e').
---
 src/echo.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/echo.c b/src/echo.c
index 58e6975..6f76d1b 100644
--- a/src/echo.c
+++ b/src/echo.c
@@ -39,7 +39,7 @@ usage (int status)
   else
     {
       printf (_("\
-Usage: %s [SHORT-OPTION]... [STRING]...\n\
+Usage: %s [SHORT-OPTION]... [--] [STRING]...\n\
   or:  %s LONG-OPTION\n\
 "), program_name, program_name);
       fputs (_("\
@@ -59,6 +59,8 @@ Echo the STRING(s) to standard output.\n\
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
       fputs (_("\
 \n\
+A '--' can be used to mark the end of SHORT-OPTIONs.\n\
+\n\
 If -e is in effect, the following sequences are recognized:\n\
 \n\
 "), stdout);
@@ -149,6 +151,12 @@ main (int argc, char **argv)
         char const *temp = argv[0] + 1;
         size_t i;
 
+        if (temp[0] == '-' && temp[1] == '\0') {
+          argc--;
+          argv++;
+          goto just_echo;
+        }
+
         /* If it appears that we are handling options, then make sure that
            all of the options specified are actually valid.  Otherwise, the
            string should just be echoed.  */
-- 
1.8.2





Added tag(s) notabug and wontfix. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Mon, 01 Apr 2013 15:36:01 GMT) Full text and rfc822 format available.

Reply sent to Eric Blake <eblake <at> redhat.com>:
You have taken responsibility. (Mon, 01 Apr 2013 15:36:02 GMT) Full text and rfc822 format available.

Notification sent to Hemmo Nieminen <hemmo.nieminen <at> iki.fi>:
bug acknowledged by developer. (Mon, 01 Apr 2013 15:36:03 GMT) Full text and rfc822 format available.

Message #12 received at 14115-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Hemmo Nieminen <hemmo.nieminen <at> iki.fi>
Cc: control <at> debbugs.gnu.org, 14115-done <at> debbugs.gnu.org
Subject: Re: bug#14115: [PATCH] echo: adding support for '--' in option parsing
Date: Mon, 01 Apr 2013 09:32:19 -0600
[Message part 1 (text/plain, inline)]
tag 14115 notabug wontfix
thanks

On 04/01/2013 03:49 AM, Hemmo Nieminen wrote:
> A '--' can now be used to mark the end of echo's options that should be
> parsed. This makes it possible to e.g. print lines where the first
> argument matches some of echo's options (e.g. 'echo -- -e').

Sorry, such behavior would violate POSIX, which special-cases 'echo' as
one of the few utilities that MUST NOT interpret '--' specially.  You
would end up breaking existing scripts that rely on POSIX semantics.
POSIX already admits that options to 'echo' are not portable, and that
you are better off using printf(1) if then thing you need to output
something that starts with a '-'.

I'm closing this bug as rejected, since we will not be applying the
patch; but you are free to continue discussing the issue.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 30 Apr 2013 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 335 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.