Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG]builtin echo error doing arguments parsing

(full quote below for reference as that was over a year ago)

I had requested the Austin Group amend the POSIX specification
to allow for echo -e, echo -E, echo -:


But (as kind of anticipated) it looks like they will add -e and
-E, but not zsh's -

https://posix@xxxxxxxxxxxxxxxxx/p/2019-04-25 (password in

So it may be worth disabling the special handling of "echo -" in
sh emulation (and keep the rest as-is). Also, maybe add a
xpg_echo alias to no_bsd_echo for bash compatibility.


2018-02-24 08:20:40 +0000, Stephane Chazelas:
> 2018-02-22 19:34:23 +0000, Peter Stephenson:
> > On Thu, 22 Feb 2018 20:00:58 +0100
> > Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > > I didn't try the patch but currently echo
> > > -- just outputs --, only - terminates options for echo.
> > 
> > Yes, the -- behaviour appears to be general behaviour, in fact,
> > so not something that should be changed.  So indeed it's hard to
> > do this at the moment in a shell script without some kind of kludge
> > for zsh.  "disable echo" and use /bin/echo might be the best bet.
> > 
> > However, I'm not really sure if that makes it less or actually more
> > useful to align with other shells (with POSIXBUILTINS) from now on...
> > it's not obvious perpetuating the need for a kludge for ever more
> > is the best bet.
> [...]
> IMO, the best thing to do here is to do nothing. Leave it as it
> is.
> The fact that - marks the end of options in zsh is documented
> and relatively well known.
> See
> https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
> That makes it one of the very few echo implementations that can
> actually output arbitrary strings reliably (the only one  if you
> consider that zsh is the only shell that can store NULs in its
> variables)
> echo -E - $var
> The only other modern implementation I'm aware of that can do
> that (in a Bourne-like shell) is yash's with its:
> ECHO_STYLE=raw echo "$var"
> To be POSIX compliant, echo -- *must* output --<nl> (-- as an
> end-of-option marker must *not* be supported), and support for
> -, -e and -E should be disabled. Also echo -nn should output
> -nn<nl>.
> However doing that would certainly break many scripts as the sh
> emulation is often used to interpret code written for bash and
> bash is also not POSIX compliant in that regard even in POSIX
> mode (unless the xpg_echo option is also enabled) as "echo -e"
> doesn't output "-e<nl>" there.
> To be UNIX compliant, no option should be recognised and -e
> should be the default.
> People already know or should already know that echo cannot be
> used for portability/reliability. It's too late to fix it and
> zsh's implementation is actually the least broken of them (for
> the very reason that it supports a way to mark the end of
> options)..
> zsh does support the POSIX printf and the ksh print which have a
> more reliable and portable API (at least when limited to the
> basic usage of echo, with the caveat that print '\01234' behaves
> differently in zsh than in other ksh implementations).
> See also https://github.com/att/ast/issues/370 for ksh93, where
> they considered changing the behaviour of echo and eventually
> backed down when considering the backward compatibility risk.
> Note that pdksh was another shell that skipped "-" arguments.
> But the "-" didn't mark the end of options, it was a bug in the
> option parsing.

Messages sorted by: Reverse Date, Date, Thread, Author