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

Re: POSIX compliance of shells - where to ask/talk about it?



Sorry for the late reply... we've been implementing scatternets :-/ and
it's been too hot to stay at home and stare at a computer at the weekend.
(Yes, it's now raining again.  Oh, and the power's just gone down, so
everybody else has gone for lunch, so I might as well finish this...)
Here is Your Handy Cut-Out-'N'-Keep Guide To Backslashing In Zsh.

Ian Lynagh wrote:
> Hi all,
> 
> Where should one ask/talk about POSIX shell compliance (looking for a
> mailing list probably)?

You're probably not going to find anything better than one of the Open
Group mailing lists, if you want the people that define the spec.  The
Austin Group is the one responsible for tinkering with Posix and other
associated standards, including the shell specification.

> printf "%s\n" `echo '\\\\\\\\\\\\\\\\'`
> printf "%s\n" "`echo '\\\\\\\\\\\\\\\\'`"
>
> ...
>
> Using shells/zsh [invoked as sh]:
> \\\\
> \\\\\\\\

There are various things going on here; in particular, both of the
options BSD_ECHO and SH_GLOB are set for Bourne shell emulation.

Here is standard zsh as a baseline:

\\\\
\\\\

The number of backslashes has been halved twice, once by the original
parsing of the backquoted expression, once by `echo' (not by the printf
"%s", of course).  The former happens because inside backquotes you can
quote backquotes, so backslashes are active.  Compare with:

% printf "%s\n" $(echo '\\\\\\\\\\\\\\\\\') 
\\\\\\\\\

Since $(...) is terminated by a parenthesis, and the parenthesis is a
standard terminator character in the shell (compare subshells with
`(...)'), no backslash-stripping happens inside; the only layer of
stripping is due to the echo.  This distinction appears to be in bash,
too.

BSD_ECHO turns off the feature that the echo builtin (but not the print
or printf builtins) interpret backslashes.  This doubles the number you
get back from the original commands:

\\\\\\\\
\\\\\\\\

I think this is probably responsible for the other differences you saw,
between bash and ash; it's certainly the difference between bash and
the Solaris 8 system here's sh, since I've just tried
  echo '\\\\\\\\\\\\\\\\'
on both and only sh halves the backquotes.  This makes sense since the
sh in this case is presumably of AT&T SYSV ancestry (the Solaris people
can correct me if I'm wrong), hence doesn't have a BSD-like echo;
/bin/echo is similar.

The option SH_GLOB makes characters which are substituted by a parameter
or command substitution elegible for further interpretation, providing
the substitution was not quoted.  In zsh, that means the number of \'s
returned when the `...` is not quoted is halved, but inside double
quotes it isn't.  This gives what you observed, viz.

\\\\
\\\\\\\\

This is definitely all a bit of a mess.  I suspect the last feature can
be regarded as a bug.  The unfortunate fact that other shells think it's
a good idea for text from parameter and command substitutions to be
processed further as patterns etc. has given no end of trouble in zsh,
and the SH_GLOB and SH_WORD_SPLIT options still don't emulate that
behaviour (which, as far as I can tell, none of the current bunch of
developers really like) properly.

Maybe that :-/ should have been :-\.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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