From: Stefano Lattarini Date: Fri, 2 Jul 2010 16:14:52 +0000 (+0200) Subject: Describe a Solaris /bin/sh bug w.r.t. for loops. X-Git-Tag: v2.66~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a20b49a348ad3be3e56fba66b1a290590e41f41f;p=thirdparty%2Fautoconf.git Describe a Solaris /bin/sh bug w.r.t. for loops. * doc/autoconf.texi (Limitations of Shell Builtins) : Document a bug of the 'for' builtin in Solaris /bin/sh, w.r.t. tokens seeming variable assignment in the list of arguments. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index c742adbf..11de524d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-07-02 Stefano Lattarini + Eric Blake + + Describe a Solaris /bin/sh bug w.r.t. for loops. + * doc/autoconf.texi (Limitations of Shell Builtins) : + 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-23 Ralf Wildenhues Improve VPATH handling in config.status for non-Automake projects. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 34ae872b..561fae8b 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -16703,6 +16703,44 @@ But keep in mind that Zsh, even in Bourne shell emulation mode, performs word splitting on @samp{$@{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}