autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Describe a Solaris /bin/sh bug w.r.t. for loops.


From: Stefano Lattarini
Subject: [PATCH] Describe a Solaris /bin/sh bug w.r.t. for loops.
Date: Fri, 2 Jul 2010 18:14:52 +0200
User-agent: KMail/1.12.1 (Linux/2.6.30-2-686; KDE/4.3.4; i686; ; )

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 <address@hidden>
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  <address@hidden>
+           Eric Blake  <address@hidden>
+
+       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  <address@hidden>
 
        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 @address@hidden"$@@"@}}; see @ref{Shell Substitutions},
 item @samp{$@@}, for more.
 
+In Solaris @command{/bin/sh}, when the list of arguments of a
address@hidden loop starts with @emph{unquoted} tokens looking like
+variable assignments, the loop is not executed on that tokens:
+
address@hidden
+$ @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
address@hidden example
+
address@hidden
+Quoting the "assignment-like" tokens, or preceding them with "normal"
+tokens, solves the problem:
+
address@hidden
+$ @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
address@hidden example
+
address@hidden
+Luckily enough, the bug is not triggered if the "assignment-like"
+tokens are the results of a variable expansion (even unquoted):
+
address@hidden
+$ @kbd{/bin/sh -c 'x="a=b"; for v in $x; do echo "$v"; done'}
+a=b
address@hidden example
+
address@hidden
+So, at least, the bug should be easy to grep for and to avoid.
 
 @anchor{if}
 @item @command{if}
-- 
1.6.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]