bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fix bug when attempting to echo special sequences literally.


From: Jim Meyering
Subject: Re: [PATCH] Fix bug when attempting to echo special sequences literally. -- [RESUBMISSION]
Date: Thu, 13 Mar 2008 11:19:22 +0100

Ondřej Vašík <address@hidden> wrote:
> Why to use it only for fist option? I would prefer to add that as option
> separator (like in attached patch). I had that issue report against Red
> Hat Enterprise Linux
> (https://bugzilla.redhat.com/show_bug.cgi?id=431005)
> and submitted following patch to Fedora Rawhide branch ~1 month ago. Was
> going to send the patch to that list, but forgot to do that...

Hi Ondřej and Adam,

The quick response is "[NOTABUG] don't change echo; use printf".

On at least freebsd, openbsd, netbsd, solaris 10, and all
other versions of Linux, "/bin/echo -- -e" prints "-- -e".
The same goes for all shell built-in "echo" functions I tried
(bash, zsh, sh, dash, ash).

It's important not to unilaterally change existing, documented behavior.
Any change in the behavior of echo (POSIX mode or default) would require
considerable justification.  Otherwise, such a change may well end up
inducing portability bugs in scripts.  Admittedly changing /bin/echo
is not as critical as changing how the various shell built-in 'echo'
functions works, but it is important nonetheless, so please revert that
change in rawhide.

The original poster wanted to print -e and -n.
POSIX has been recommending to use printf (rather than echo) for over
15 years, and coreutils' "info echo" has been saying that for more than 3:

       If the `POSIXLY_CORRECT' environment variable is set, then when
    `echo''s first argument is not `-n' it outputs option-like arguments
    instead of treating them as options.  For example, `echo -ne hello'
    outputs `-ne hello' instead of plain `hello'.

       POSIX does not require support for any options, and says that the
    behavior of `echo' is implementation-defined if any STRING contains a
    backslash or if the first argument is `-n'.  Portable programs can use
    the `printf' command if they need to omit trailing newlines or output
    control characters or backslashes.  *Note printf invocation::.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]