Thu, 7 Apr 2016 19:15:51 +0200 Christian Weisgerber <[email protected]>
> Let's illustrate the issue:
> 
> $ sh          -c 'echo "`echo \"hi\"`"'
> hi
> $ sh -o posix -c 'echo "`echo \"hi\"`"'
> "hi"

It is important this is consistently verified in evaluations, here
strings, here docs, filters, pipes, streams, aliases, functions and
other (less) advanced (k)sh constructs.  Thank you for considering
these other use cases and related changes to escaping with quotes.

> I'll just quote ksh.1:
> 
>  o   Occurrences of \" inside double quoted `..` command substitutions.
>      In POSIX mode, the \" is interpreted when the command is interpreted;
>      in non-POSIX mode, the backslash is stripped before the command
>      substitution is interpreted.  For example, echo "`echo \"hi\"`"
>      produces ``"hi"'' in POSIX mode, ``hi'' in non-POSIX mode.  To avoid
>      problems, use the $(...) form of command substitution.
> 
> From time to time there's a configure script in ports that sets -o
> posix but expects the other behavior, because other popular shells
> do not share this interpretation of what POSIX mandates.  bash,
> whether in POSIX mode or not, and FreeBSD's sh always strip the
> backslashes.

Of course, if the general movement is towards changing a particular
point in the standard, based on wide adoption and movement in that
direction already, there is no point in waiting for POSIX to react.

While I particularly have no strong preference, it is also important
for for all shell script users and applications to have a consistent
expected behaviour on our system, and not have ports or other systems
introduce changes to us for a sidetrack from standards that would 
eventually create more points of deviation and mind load user end.

> On reading the POSIX text, I find the ksh author's interpretation
> far-fetched.  See also:
> http://austingroupbugs.net/view.php?id=1015
> 
> Regardless of what you contend the standard text says, I think it
> is clear that the other interpretation has won out in practice and
> I propose to align our ksh with that:
> 
> Index: lex.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.68
> diff -u -p -r1.68 lex.c
> --- lex.c     4 Mar 2016 09:37:23 -0000       1.68
> +++ lex.c     7 Apr 2016 16:18:13 -0000
> @@ -427,40 +427,22 @@ yylex(int cf)
>                               /* Need to know if we are inside double quotes
>                                * since sh/at&t-ksh translate the \" to " in
>                                * "`..\"..`".
> -                              * This is not done in posix mode (section
> -                              * 3.2.3, Double Quotes: "The backquote shall
> -                              * retain its special meaning introducing the
> -                              * other form of command substitution (see
> -                              * 3.6.3). The portion of the quoted string
> -                              * from the initial backquote and the
> -                              * characters up to the next backquote that
> -                              * is not preceded by a backslash (having
> -                              * escape characters removed) defines that
> -                              * command whose output replaces `...` when
> -                              * the word is expanded."
> -                              * Section 3.6.3, Command Substitution:
> -                              * "Within the backquoted style of command
> -                              * substitution, backslash shall retain its
> -                              * literal meaning, except when followed by
> -                              * $ ` \.").
>                                */
>                               statep->ls_sbquote.indquotes = 0;
> -                             if (!Flag(FPOSIX)) {
> -                                     Lex_state *s = statep;
> -                                     Lex_state *base = state_info.base;
> -                                     while (1) {
> -                                             for (; s != base; s--) {
> -                                                     if (s->ls_state == 
> SDQUOTE) {
> -                                                             
> statep->ls_sbquote.indquotes = 1;
> -                                                             break;
> -                                                     }
> -                                             }
> -                                             if (s != base)
> -                                                     break;
> -                                             if (!(s = s->ls_info.base))
> +                             Lex_state *s = statep;
> +                             Lex_state *base = state_info.base;
> +                             while (1) {
> +                                     for (; s != base; s--) {
> +                                             if (s->ls_state == SDQUOTE) {
> +                                                     
> statep->ls_sbquote.indquotes = 1;
>                                                       break;
> -                                             base = s-- - STATE_BSIZE;
> +                                             }
>                                       }
> +                                     if (s != base)
> +                                             break;
> +                                     if (!(s = s->ls_info.base))
> +                                             break;
> +                                     base = s-- - STATE_BSIZE;
>                               }
>                               break;
>                       default:
> Index: ksh.1
> ===================================================================
> RCS file: /cvs/src/bin/ksh/ksh.1,v
> retrieving revision 1.178
> diff -u -p -r1.178 ksh.1
> --- ksh.1     21 Mar 2016 13:35:00 -0000      1.178
> +++ ksh.1     7 Apr 2016 16:10:58 -0000
> @@ -822,12 +822,6 @@ the
>  and the newline are stripped; otherwise, both the
>  .Ql \e
>  and the character following are unchanged.
> -.Pp
> -.Sy Note :
> -See
> -.Sx POSIX mode
> -below for a special rule regarding
> -differences in quoting when the shell is in POSIX mode.
>  .Ss Aliases
>  There are two types of aliases: normal command aliases and tracked aliases.
>  Command aliases are normally used as a short hand for a long or often used
> @@ -2472,27 +2466,6 @@ The following is a list of things that a
>  .Ic posix
>  option:
>  .Bl -bullet
> -.It
> -Occurrences of
> -.Ic \e\&"
> -inside double quoted
> -.Ic `..`
> -command substitutions.
> -In POSIX mode, the
> -.Ic \e\&"
> -is interpreted when the command is interpreted;
> -in non-POSIX mode,
> -the backslash is stripped before the command substitution is interpreted.
> -For example,
> -.Ic echo \&"`echo \e\&"hi\e\&"`\&"
> -produces
> -.Dq \&"hi\&"
> -in POSIX mode,
> -.Dq hi
> -in non-POSIX mode.
> -To avoid problems, use the
> -.Ic $(...)\&
> -form of command substitution.
>  .It
>  .Ic kill -l
>  output.

Reply via email to