zsh-workers
 help / color / mirror / code / Atom feed
* Expansion/quoting quirks
@ 1995-11-05 13:00 Thorsten Meinecke
  1995-11-05 18:26 ` Barton E. Schaefer
  1995-11-06 17:25 ` Zoltan Hidvegi
  0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Meinecke @ 1995-11-05 13:00 UTC (permalink / raw)
  To: zsh-workers

Hello,

albeit Zoltan's claims of improved sh-compatibility are almost true,
there is still a serious bug in his release that prevents the ${1+"$@"}
idiom from doing the right thing, because quoted arguments with embedded
whitespace are split despite their quotes. To demonstrate this bug and a
few other possible problems I threw together a tiny test script, which is
appended below.

Incidentally, the only shell I have access to, which passes all the tests
of my script, is `PD KSH v5.1.3 94/12/22'. Even bash has trouble with null
args. Other contestants were 2.6-beta11-test12 and 2.6-beta11-test9-hzoli11,
each of them invoked as `./sh -f' and `./ksh -f', respectively.

Save as `expbug', set symlinks from sh (and ksh) to zsh, and execute with
`expbug ./sh -f', for example. The testee is running as a coprocess, and
its output will be compared to the expected output, which is on the lines
beginning with `#%'. Sample output (for hzoli) looks like this:


  $ ~/expbug ./ksh -f
  Testing ./ksh -f ...
  1c1
  < \
  ---
  > 
  7c7
  < argc=1, argv=( 'a b' )
  ---
  > argc=2, argv=( 'a' 'b' )
  9a10
  > argc=4, argv=( 'a' 'b' '' 'c' )
  11,12c12
  < argc=3, argv=( 'a b' '' 'c' )
  < argc=3, argv=( 'a b' '' 'c' )
  ---
  > zsh: closing brace expected

  Not OK, output left in file /tmp/zshtest18454


If I'm missing something, I'm sure, you'll tell me. :-)
--Thorsten

==================== cut here ==================== 
#!/bin/zsh -f
# expbug: a few (k)sh-compatibility tests
( 
    TEMP=${TMPPREFIX}test$$
    if (( $# ))
    then
        WHAT=($@)
    else
        WHAT=(zsh -f)
    fi
    echo "Testing $WHAT ..."
    coproc 2>&1 $WHAT
    sed -ne "/^#/!p" -e "s/^#%[ ]*//w $TEMP" >&p
    if <&p cat -v | diff $TEMP -
    then
        echo OK.
        rm -f $TEMP
        exit 0
    else
        echo "\nNot OK, output left in file $TEMP"
        exit 1
    fi
) <<\EOF

# Command substitution eats too much backslashes
#% \
echo `echo \\\\`    # broken in hzoli, and in vanilla zsh if invoked as (k)sh
#% \
echo $(echo \\\\)
#% \
echo "$(echo \\\\)" # sh and ksh seem to differ here (bash would give `\\')

# Single quotes aren't recognized (fixed in hzoli)
#% $foo
foo=10 x=foo
y='$'$x
echo $y

# Backslash ignored between single quotes (fixed in hzoli)
#% \$x
echo $(echo '\$x')


# nargs(): A function which neatly prints the arguments passed to it
nargs () {
  echo -n "argc=$#, argv=( "
  while [ $# -ne 0 ]; do
    echo -n "'$1' "
    shift
  done
  echo ")"
}

#% argc=2, argv=( 'a' 'b' )
nargs ${undef-a b}
#% argc=1, argv=( 'a b' )
nargs ${undef-"a b"}             # vanilla + hzoli: shouldn't split here
#% argc=1, argv=( 'a b' )
nargs "${undef-a b}"

# The following are broken in vanilla

set "a b" "" c

#% argc=3, argv=( 'a' 'b' 'c' )
nargs ${undef-$@}                # This works in hzoli's sh-mode 

#% argc=3, argv=( 'a b' '' 'c' )
nargs ${undef-"$@"}              # hzoli: 'a b' shouldn't split into 'a' 'b'

#% argc=3, argv=( 'a b' '' 'c' )
nargs "${undef-$@}"              # This works also in hzoli's sh-mode

#% argc=3, argv=( 'a b' '' 'c' )
nargs "${undef-"$@"}"            # hzoli: zsh: closing brace expected

exit
EOF
==================== cut here ==================== 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1995-11-06 18:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-11-05 13:00 Expansion/quoting quirks Thorsten Meinecke
1995-11-05 18:26 ` Barton E. Schaefer
1995-11-06 15:39   ` Zoltan Hidvegi
1995-11-06 17:25 ` Zoltan Hidvegi

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).