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

Re: Interesting zsh behaviour regarding awk and backslash



2011-09-27 06:48:22 -0700, Bart Schaefer:
> On Sep 27,  1:54pm, Jeremie Roquet wrote:
> }
> } Why bother with gawk?
> } 
> } bash$ echo '\\'
> } \\
> } zsh$ echo '\\'
> } \
> 
> This isn't quoting behavior, it's "echo" behavior.  If you tell zsh to
> act like a standard shell, it does:
> 
> % ARGV0=sh zsh -f
> $ echo '\\'
> \\
> $  set -o | grep echo
> nobsdecho             off
> $ 

standard shells *are meant* to output "\", not "\\". bash is not
standard in that regard. So zsh should *not* change its behavior
when called as sh here.

UNIX (POSIX+XSI) mandates the "\", POSIX makes the behavior of
echo unspecified in that case ("\", "\\" and "ambiguous input"
outputs are all acceptable, echo shouldn't be used in POSIX
scripts where the arguments may contain "\" or start with "-n"
(use printf instead))

zsh is not POSIX (and same for bash) in that it doesn't
output "-e" when called as "echo -e".

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
for the spec.

-- 
Stephane



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