From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17289 invoked by alias); 3 Aug 2010 21:21:11 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28124 Received: (qmail 6176 invoked from network); 3 Aug 2010 21:21:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.214.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=+Eu9SKx1p/rDQaDVl45HbQyoJBxoOuZvA22P0q0sa+8=; b=Xqgz17rK3D90uRCrBHNYpZAIkU1EuaA0ygDnmVX4m/NEnhAxwESYHs86RzvU6DpL5n QFtlmLjeolgffy6NErI0mHkluvLj2f6MFwoOhiCFZ4c2o729IGLdjKZXXbpSmqEImRsV oWaf6/LvRFEVreiUWJCRuptljisbztYmBTJQM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=n7QOkrY4bwTel+rtHTbk9hRPgtDt6S1Y0QU4ZRBFMHG6QwL8jzI6MYI7JZ4DhcMVvb AZjDrOhsZU+h8Ci+sTMrB4YiIT8WZ189Sr7xnrAdMmZhX/imK5ZipOHA2MSXbRmqI9gs 7Vfm2kVwkrQIDTp8Y7+dJIo6Eh43TmYZDTxms= MIME-Version: 1.0 In-Reply-To: <4C588248.9050807@redhat.com> References: <20100803203204.GG13690@gmx.de> <4C588248.9050807@redhat.com> Date: Tue, 3 Aug 2010 23:21:02 +0200 Message-ID: Subject: Re: Fix testsuite errors due to shell quoted parameter expansion issue. From: Mikael Magnusson To: Eric Blake Cc: libtool-patches@gnu.org, gary@gnu.org, zsh-workers@zsh.org, Autoconf@gnu.org Content-Type: text/plain; charset=UTF-8 On 3 August 2010 22:55, Eric Blake wrote: > [adding autoconf to document some shell bugs] > > On 08/03/2010 02:32 PM, Ralf Wildenhues wrote: >> Interesting shell unportability: >> >> $ bash -c 'f=" val" e=; echo "$e"$f' >> val >> $ ksh -c 'f=" val" e=; echo "$e"$f' >> val >> >> ksh93, dash, zsh all do it like ksh. Is that a bug in bash? > > Yes; adding bug-bash accordingly. According to POSIX: > > http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 > > "After parameter expansion ( Parameter Expansion ), command substitution > ( Command Substitution ), and arithmetic expansion ( Arithmetic > Expansion ), the shell shall scan the results of expansions and > substitutions that did not occur in double-quotes for field splitting > and multiple fields can result." > > Since $f is not quoted, its expansion must undergo field splitting. But > since "$e" is quoted, it must not be elided even though empty. The > result must be _two_ fields, as if you had done "echo '' 'val'". > > But it is _also_ a bug in zsh; adding zsh-workers accordingly. > > $ zsh -cvx 'f=" val" e=; echo "$e"$f' > +zsh:1> f=' val' e='' > +zsh:1> echo ' val' > val > > Oops - zsh only passed one argument to echo, with a leading space, > instead of passing an empty argument and letting echo supply the space. > ksh93, pdksh, and dash get it right (although dash doesn't use quotes > in -vx output, hence my use of n() to force things to tell; n() is > another way to expose the bash and zsh bugs). zsh doesn't do word splitting by default, you can enable it with the = modifier: % zsh -fcvx 'f=" val" e=; echo "$e"$=f' +zsh:1> f=' val' e='' +zsh:1> echo '' val val does what you want Alternatively you can make zsh try to be closer to sh by setting argv[0] to sh when executing it, or running 'emulate sh' as the first command (and possibly other ways I don't know about): % zsh -fcvx 'emulate sh;f=" val" e=; echo "$e"$f' +zsh:1> emulate sh +zsh:1> f=' val' e='' +zsh:1> echo '' val val There's also --shwordsplit for this specific case: % zsh --shwordsplit -fcvx 'f=" val" e=; echo "$e"$f' +zsh:1> f=' val' e='' +zsh:1> echo '' val val (the -f above only avoids loading my .zshenv which would spam my output) -- Mikael Magnusson