GNU bug report logs -
#21416
"--" syntax for ignoring flags doesn't seem to work right with GNU /bin/echo
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21416 in the body.
You can then email your comments to 21416 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#21416
; Package
coreutils
.
(Fri, 04 Sep 2015 19:11:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
"Robert \"Finny\" Merrill" <rfm <at> arista.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Fri, 04 Sep 2015 19:11:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
~/workspaces/diags-dev/s1 @bs360.sjc> /bin/echo --help
Usage: /bin/echo [SHORT-OPTION]... [STRING]...
or: /bin/echo LONG-OPTION
Echo the STRING(s) to standard output.
*snip*
~/workspaces/diags-dev/s1 @bs360.sjc> /bin/echo -- --help
-- --help
~/workspaces/diags-dev/s1 @bs360.sjc>
There doesn't seem to be a way to get /bin/echo to output the string "--help"
Added tag(s) notabug.
Request was from
Eric Blake <eblake <at> redhat.com>
to
control <at> debbugs.gnu.org
.
(Fri, 04 Sep 2015 19:27:02 GMT)
Full text and
rfc822 format available.
Reply sent
to
Eric Blake <eblake <at> redhat.com>
:
You have taken responsibility.
(Fri, 04 Sep 2015 19:27:03 GMT)
Full text and
rfc822 format available.
Notification sent
to
"Robert \"Finny\" Merrill" <rfm <at> arista.com>
:
bug acknowledged by developer.
(Fri, 04 Sep 2015 19:27:03 GMT)
Full text and
rfc822 format available.
Message #12 received at 21416-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
tag 21416 notabug
thanks
On 09/04/2015 12:57 PM, Robert "Finny" Merrill wrote:
> ~/workspaces/diags-dev/s1 @bs360.sjc> /bin/echo --help
> Usage: /bin/echo [SHORT-OPTION]... [STRING]...
> or: /bin/echo LONG-OPTION
> Echo the STRING(s) to standard output.
> *snip*
This is a GNU extension; it is not POSIX compliant, but can easily be
overridden, as shown below.
> ~/workspaces/diags-dev/s1 @bs360.sjc> /bin/echo -- --help
> -- --help
Thanks for the report. However, this is working as required by POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
"The echo utility shall not recognize the "--" argument in the
manner specified by Guideline 10 of XBD Utility Syntax Guidelines; "--"
shall be recognized as a string operand."
"Implementations shall not support any options."
>
> There doesn't seem to be a way to get /bin/echo to output the string "--help"
Ah, but there is:
$ POSIXLY_CORRECT=1 /bin/echo --help
--help
Also, POSIX says that 'echo' is outdated (not only because it violates
the standard syntax rules, but also because it has non-portable handling
of \), and that you should strongly consider using printf, in which
case, you would do:
$ printf -- %s\\n --help
--help
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#21416
; Package
coreutils
.
(Fri, 04 Sep 2015 22:06:01 GMT)
Full text and
rfc822 format available.
Message #15 received at 21416-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 09/04/2015 01:30 PM, Robert "Finny" Merrill wrote:
> unicasting so it doesn't reopen the bug:
[re-adding the list with permission]
The bug-tracker is perfectly fine with adding additional comments even
to a closed bug; merely replying doesn't reopen a bug report.
>
> If POSIX says not to recognize "--" doesn't "not recognize" mean it
> shouldn't do anything at all? In that case, you're not actually
> following it since -- causes different behavior :)
You've quoted incomplete context, which changed the meaning.
>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
>>
>> "The echo utility shall not recognize the "--" argument in the
>> manner specified by Guideline 10 of XBD Utility Syntax Guidelines; "--"
>> shall be recognized as a string operand."
>>
>> "Implementations shall not support any options."
It's not "shall not be recognized [ever]", but "shall not be recognized
in the manner [common to most utilities]. The very next phrase says
that it "shall be recognized as a string operand".
Or put another way, as a special case for the 'echo' utility, '--' shall
be treated the same as any other argument, and always be output
literally, rather than being recognized as the special elided
end-of-options marker, because 'echo' does not understand options (at
least when POSIX rules are in effect).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#21416
; Package
coreutils
.
(Fri, 04 Sep 2015 22:24:01 GMT)
Full text and
rfc822 format available.
Message #18 received at 21416-done <at> debbugs.gnu.org (full text, mbox):
On Fri, Sep 4, 2015 at 3:05 PM, Eric Blake <eblake <at> redhat.com> wrote:
> On 09/04/2015 01:30 PM, Robert "Finny" Merrill wrote:
> It's not "shall not be recognized [ever]", but "shall not be recognized
> in the manner [common to most utilities]. The very next phrase says
> that it "shall be recognized as a string operand".
>
> Or put another way, as a special case for the 'echo' utility, '--' shall
> be treated the same as any other argument, and always be output
> literally, rather than being recognized as the special elided
> end-of-options marker, because 'echo' does not understand options (at
> least when POSIX rules are in effect).
So then, when POSIX rules /aren't/ in effect, why not have -- work as
it usually does, since we're already breaking those rules by accepting
the --help option?
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#21416
; Package
coreutils
.
(Fri, 04 Sep 2015 22:35:02 GMT)
Full text and
rfc822 format available.
Message #21 received at 21416-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 09/04/2015 04:23 PM, Robert "Finny" Merrill wrote:
> On Fri, Sep 4, 2015 at 3:05 PM, Eric Blake <eblake <at> redhat.com> wrote:
>> On 09/04/2015 01:30 PM, Robert "Finny" Merrill wrote:
>> It's not "shall not be recognized [ever]", but "shall not be recognized
>> in the manner [common to most utilities]. The very next phrase says
>> that it "shall be recognized as a string operand".
>>
>> Or put another way, as a special case for the 'echo' utility, '--' shall
>> be treated the same as any other argument, and always be output
>> literally, rather than being recognized as the special elided
>> end-of-options marker, because 'echo' does not understand options (at
>> least when POSIX rules are in effect).
>
> So then, when POSIX rules /aren't/ in effect, why not have -- work as
> it usually does, since we're already breaking those rules by accepting
> the --help option?
Because then coreutils' echo would needlessly differ from bash's echo,
and because who knows what existing scripts have come to rely on the
behavior and might break as a result. The use of
POSIXLY_CORRECT=anything to change behavior is not something done
lightly, and we are loathe to make it control more than a bare minimum
of behavior changes.
[As it is, bash has a bug:
$ (shopt -s xpg_echo; echo -e)
should output '-e', but currently outputs nothing. Also, bash does not
quite treat POSIXLY_CORRECT=1 (also spelled 'set -o posix') as the
override to turn on full POSIX compliance, as it leaves xpg_echo as a
separate knob; ideally, turning on posix compliance in bash should turn
on xpg_echo - but enough people are used to the old behavior that it was
decided to keep the knobs separate]
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#21416
; Package
coreutils
.
(Fri, 04 Sep 2015 22:43:01 GMT)
Full text and
rfc822 format available.
Message #24 received at 21416-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 09/04/2015 04:34 PM, Eric Blake wrote:
> [As it is, bash has a bug:
> $ (shopt -s xpg_echo; echo -e)
>
> should output '-e', but currently outputs nothing. Also, bash does not
> quite treat POSIXLY_CORRECT=1 (also spelled 'set -o posix') as the
> override to turn on full POSIX compliance, as it leaves xpg_echo as a
> separate knob; ideally, turning on posix compliance in bash should turn
> on xpg_echo - but enough people are used to the old behavior that it was
> decided to keep the knobs separate]
Maybe I spoke too soon. It looks like bash needs BOTH xpg_echo and posix
mode at the same time, either one in isolation is not enough:
$ for opt in '' 'shopt -s xpg_echo' 'set -o posix' \
'shopt -s xpg_echo; set -o posix'; do
bash -c "echo 'trying $opt'; ${opt:-:}; echo -e"
done
trying
trying shopt -s xpg_echo
trying set -o posix
trying shopt -s xpg_echo; set -o posix
-e
$
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#21416
; Package
coreutils
.
(Sat, 05 Sep 2015 01:23:02 GMT)
Full text and
rfc822 format available.
Message #27 received at 21416 <at> debbugs.gnu.org (full text, mbox):
Robert "Finny" Merrill wrote:
> ~/workspaces/diags-dev/s1 @bs360.sjc> /bin/echo --help
> Usage: /bin/echo [SHORT-OPTION]... [STRING]...
> or: /bin/echo LONG-OPTION
> Echo the STRING(s) to standard output.
> *snip*
> ~/workspaces/diags-dev/s1 @bs360.sjc> /bin/echo -- --help
> -- --help
> ~/workspaces/diags-dev/s1 @bs360.sjc>
Under what actual live conditions in the wild would someone be using
/bin/echo in this manor?
Most shell interpreters used for scripts will have a shell builtin
version of echo.
$ ls -log /bin/sh
lrwxrwxrwx 1 4 Nov 8 2014 /bin/sh -> dash
$ /bin/sh -c 'echo --help'
--help
$ /bin/bash -c 'echo --help'
--help
$ /bin/ash -c 'echo --help'
--help
$ /bin/dash -c 'echo --help'
--help
$ /bin/ksh -c 'echo --help'
--help
$ /bin/csh -c 'echo --help'
--help
I think this might be a problem that is purely academic as it can't
ever actually be hit in real life. However if you provide an actual
example that would go a long way to making this problem clear.
> There doesn't seem to be a way to get /bin/echo to output the string "--help"
Woe is me for suggesting using -e or -E as they are terribly
non-portable options. Don't use them! Use printf instead. But
having said that...
$ /bin/echo -e --help
--help
$ /bin/echo -E --help
--help
But please don't do it. Use printf instead. The shell printf command
has a standard syntax and may portably be used.
Bob
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 03 Oct 2015 11:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 9 years and 265 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.