Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Zsh 3 and ${1+"$@"} (Was: [GNU Autoconf 2.53] testsuite.log: 126 failures)
- X-seq: zsh-workers 16945
- From: Peter Stephenson <pws@xxxxxxx>
- To: Akim Demaille <akim@xxxxxxxx>
- Subject: Re: Zsh 3 and ${1+"$@"} (Was: [GNU Autoconf 2.53] testsuite.log: 126 failures)
- Date: Tue, 09 Apr 2002 11:35:43 +0100
- Cc: zsh-workers@xxxxxxxxxx, ab@xxxxxxxxxx, bug-autoconf@xxxxxxx
- In-reply-to: "Akim Demaille"'s message of "09 Apr 2002 11:45:11 +0200." <mv4pu19xl20.fsf@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Akim Demaille wrote:
> Hi!
>
> We (Autoconf) have a big problem with Zsh 3.0.8. You know it is
> shipped on Darwin as /bin/sh. But this version does not understand
> ${1+"$@"} properly. We use this instead of "$@" to work around a bug
> which still exists today in many many constructors' /bin/sh, so we
> can't departure from it.
I think the problem you are running across is that with the option
SH_WORD_SPLIT set (as it is for sh compatibility), you get this behaviour:
% set 'one two'
% for arg in ${1+"$@"}; do echo $arg; done
one
two
whereas you expect `one two' on the same line. This problem is still in
zsh 4 --- inside another substitution, either it's splitting all words
on spaces, or it's splitting none.
This sort of mess is why zsh doesn't have SH_WORD_SPLIT on by default,
but that doesn't help you...
If you want to work around this you have two basic choices:
1. Unset shwordsplit:
[ x$ZSH_VERSION != x ] && unsetopt shwordsplit
This will have a knock on effect on all unquoted shell parameter
substitutions, however. If you are relying on these producing multiple
command arguments --- e.g. for building up arguments for `for' loops in
a single parameter --- you are stuck unless you can find some way of
turning shwordsplit off and on before using ${1+"$@"}. (Writers of
configure scripts --- not autoconf itself --- often incorrectly assume
something like `test x$foo != x' will always produce the same number of
words, but that's a separate problem from the one you face.)
2. Rework the substitution. In zsh, you would get away with
${==1+"$@"}, since the doubled `=' is a flag to turn off SH_WORD_SPLIT
for that substitution. Obviously, getting this in for zsh and not for
other shells is a bit of a nightmare. Indeed, rather than do that, it
would presumably be easier to use "$@" for zsh instead of ${1+"$@"}
(this handles zero arguments correctly), which is exactly what you're
trying to avoid.
Neither of these looks very promising.
"${1+"$@"}" also works in zsh, but this confuses other variants of sh
--- it works in bash, but sh on SunOS 5.8 tripped over it.
I haven't looked for any cleverer substitutions which will always work.
Given that ${1+"$@"} is already a despairing workaround, it seems
unlikely there's anything more complicated which will fool everyone at
once.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author