zsh-workers
 help / color / mirror / code / Atom feed
From: Thorsten Meinecke <kaefer@aglaia.snafu.de>
To: zsh-workers@math.gatech.edu
Subject: Expansion/quoting quirks
Date: Sun, 5 Nov 1995 14:00:27 +0100 (MET)	[thread overview]
Message-ID: <m0tC4gW-00007BC@aglaia.snafu.DE> (raw)

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 ==================== 


             reply	other threads:[~1995-11-05 13:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-11-05 13:00 Thorsten Meinecke [this message]
1995-11-05 18:26 ` Barton E. Schaefer
1995-11-06 15:39   ` Zoltan Hidvegi
1995-11-06 17:25 ` Zoltan Hidvegi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0tC4gW-00007BC@aglaia.snafu.DE \
    --to=kaefer@aglaia.snafu.de \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).