[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: echo builtin doesn't handle end-of-options flag
From: |
Eric Blake |
Subject: |
Re: echo builtin doesn't handle end-of-options flag |
Date: |
Sun, 16 Aug 2020 11:21:23 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
On 8/16/20 10:47 AM, Todd A. Jacobs wrote:
Description:
The echo builtin accepts options, but does not seem to handle
`--` correctly as the end of options.
The correct behavior for echo is described here:
https://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."
The expected behavior
would be for -- to be removed, and any following flag-like
substrings printed as-is.
Your expectations are wrong, they contradict what POSIX says.
Repeat-By:
echo "-n" # "" but expecting "-n"
POSIX says this one is implementation-defined; so whether -n is treated
as an option or as a string to echo has to be documented by the
implementation (bash documents treating it as an option).
echo -- -n foo # -- -n foo
POSIX says this has to output '-- -n foo' and a newline. -n wasn't
first, so you no longer have the implementation-defined behavior, but
well-defined.
echo -- "-n foo" # -- -n foo
Also well-defined.
I see nothing in your report about bash disobeying POSIX, but rather
confusion on your part about what POSIX actually requires.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org