Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Fix testsuite errors due to shell quoted parameter expansion issue.
- X-seq: zsh-workers 28124
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Eric Blake <eblake@xxxxxxxxxx>
- Subject: Re: Fix testsuite errors due to shell quoted parameter expansion issue.
- Date: Tue, 3 Aug 2010 23:21:02 +0200
- Cc: libtool-patches@xxxxxxx, gary@xxxxxxx, zsh-workers@xxxxxxx, Autoconf@xxxxxxx
- 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=
- In-reply-to: <4C588248.9050807@xxxxxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20100803203204.GG13690@xxxxxx> <4C588248.9050807@xxxxxxxxxx>
On 3 August 2010 22:55, Eric Blake <eblake@xxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author