Subject: bin/26493: pdksh misinterpretation of posix
To: None <>
From: None <>
List: netbsd-bugs
Date: 07/31/2004 18:39:37
>Number:         26493
>Category:       bin
>Synopsis:       bug in pdksh backquote substitution
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 31 17:40:00 UTC 2004
>Originator:     Patrick Welche
>Release:        NetBSD 2.0G
@(#)PD KSH v5.2.14 99/07/13.2
from NetBSD-2.0G/i386
The autotools wizards have shown me the error of our ksh's ways, and
pointed me to

                 The Open Group Base Specifications Issue 6
                       IEEE Std 1003.1, 2004 Edition

  2.2 Quoting

    2.2.3 Double-Quotes

   Enclosing characters in double-quotes ( "" ) shall preserve the
   literal value of all characters within the double-quotes, with the
   exception of the characters dollar sign, backquote, and backslash, as
          The backquote shall retain its special meaning introducing the
          other form of command substitution (see Command Substitution ).
          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. Either of the following cases produces undefined
          + A single-quoted or double-quoted string that begins, but does 
            not end, within the "`...`" sequence
          + A "`...`" sequence that begins, but does not end, within the
            same double-quoted string

which is directly in opposition to what our ksh(1) man page says:

       The following is a list of things that are affected by the state of the
       posix option:
         o    \"  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.

Looking at the standard above (c.f. "having escape characters
removed"), in posix mode, the command executed should be |echo "hi"|,
leading to |hi| being printed, (| used as quote) not |"hi"|.
This is in direct contradition to the man page..  (The shell's
behaviour is in accordance with the man page)
- Need to agree that ksh's interpretation of POSIX is incorrect
- Then just look at line 326 of lex.c (v.1.10) where the assertion that
  the string doesn't have escape characters removed in posix mode is