coreutils
[Top][All Lists]
Advanced

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

Re: feature request: echo --


From: Bob Proulx
Subject: Re: feature request: echo --
Date: Tue, 19 Oct 2021 01:06:12 -0600

Florent Flament wrote:
> Out of curiosity, would it possible to have the `echo` command output
> the string "-n" ?
> 
> ```
> $ POSIXLY_CORRECT=1 /bin/echo -n
> ```

But the standards do actually mention -n.  The behavior you see with
POSIXLY_CORRECT=1 is conforming behavior.

    
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html#tag_20_37

    If the first operand is -n, or if any of the operands contain a <backslash>
    character, the results are implementation-defined.

Unix v7 echo accepted -n as an option and did not print it.  Same with
BSD.  It is too late to mess with it now.

On a practical level why is it an issue at all?  If there is any
concern about printing -n then use 'printf' as that is a much better
solution for arbitrary strings.

Also note that most shells include 'echo' as a builtin command which
will be different from the coreutils standalone executable.  Most
users should look to their shell for their echo implementation instead.

Bob



reply via email to

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