At Thursday 01 July 2010, Eric Blake wrote: > On 07/01/2010 05:42 AM, Stefano Lattarini wrote: > > Hello autoconfers. > > > > Is anyone aware of the following bug of Solaris /bin/sh w.r.t. > > for loops? I couldn't find any mention of it in the Autoconf > > manual, and I think that a proper description of the bug could be > > an useful addition for the manual. > > $ /bin/sh -c 'for a in b=c x; do echo "$a"; done' > > x > > Freaky! And yes, I confirmed that behavior. > > No, I've never seen this bug mentioned before, and yes, mentioning > it in > > the manual would be worthwhile. Thankfully, since: > > $ /bin/sh -c 'x="b=c"; for a in $x; do echo "$a"; done' > > b=c > > the bug only strikes for a word that looks like an assignment, and > not an expansion that ends up looking like an assignment, which > means it should be easy to a) grep for, and b) avoid. > > Would you care to prepare a patch? Here it is (see attachement). I'm not sure I worded it the best way, though, so suggestions and criticism from native speakers are very welcome.
Regards, Stefano
From ff3be588997624463e75b66b2bee35b5d5fd8f6a Mon Sep 17 00:00:00 2001 From: Stefano Lattarini <stefano.lattar...@gmail.com> Date: Fri, 2 Jul 2010 18:05:51 +0200 Subject: [PATCH] Describe a Solaris /bin/sh bug w.r.t. for loops. * doc/autoconf.texi (Limitations of Shell Builtins) <for>: Document a bug of the 'for' builtin in Solaris /bin/sh, w.r.t. tokens seeming variable assignment in the list of arguments. Report and final patch by Stefano Lattarini, useful suggestions by Eric Blake. --- ChangeLog | 10 ++++++++++ doc/autoconf.texi | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index fac7c04..7652bb5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-07-02 Stefano Lattarini <stefano.lattar...@gmail.com> + Eric Blake <ebl...@redhat.com> + + Describe a Solaris /bin/sh bug w.r.t. for loops. + * doc/autoconf.texi (Limitations of Shell Builtins) <for>: + Document a bug of the 'for' builtin in Solaris /bin/sh, w.r.t. + tokens seeming variable assignment in the list of arguments. + Report and final patch by Stefano Lattarini, useful suggestions + by Eric Blake. + 2010-06-01 Ralf Wildenhues <ralf.wildenh...@gmx.de> Documentation and tests for the AC_CHECK_DECL change. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index eab9ab2..afa180e 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -16668,6 +16668,44 @@ But keep in mind that Zsh, even in Bourne shell emulation mode, performs word splitting on @sam...@{1+"$@@"@}}; see @ref{Shell Substitutions}, item @samp{$@@}, for more. +In Solaris @command{/bin/sh}, when the list of arguments of a +...@command{for} loop starts with @emph{unquoted} tokens looking like +variable assignments, the loop is not executed on that tokens: + +...@example +$ @kbd{/bin/sh -c 'for v in a=b; do echo "$v"; done'} +$ @kbd{/bin/sh -c 'for v in a=b d=c; do echo "$v"; done'} +$ @kbd{/bin/sh -c 'for v in a=b x; do echo "$v"; done'} +x +...@end example + +...@noindent +Quoting the "assignment-like" tokens, or preceding them with "normal" +tokens, solves the problem: + +...@example +$ @kbd{/bin/sh -c 'for v in "a=b"; do echo "$v"; done'} +a=b +$ @kbd{/bin/sh -c 'for v in x a=b; do echo "$v"; done'} +x +a=b +$ @kbd{/bin/sh -c 'for v in x a=b d=c; do echo "$v"; done'} +x +a=b +c=d +...@end example + +...@noindent +Luckily enough, the bug is not triggered if the "assignment-like" +tokens are the results of a variable expansion (even unquoted): + +...@example +$ @kbd{/bin/sh -c 'x="a=b"; for v in $x; do echo "$v"; done'} +a=b +...@end example + +...@noindent +So, at least, the bug should be easy to grep for and to avoid. @anchor{if} @item @command{if} -- 1.6.5