GNU bug report logs - #20733
coreutils build problem

Previous Next

Package: coreutils;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Thu, 4 Jun 2015 19:18:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: autoconf-patches <at> gnu.org
Cc: 20733 <at> debbugs.gnu.org, mamfelt <at> gmail.com
Subject: bug#20733: [PATCH] doc: mention 'for' syntax issue on older shells
Date: Thu,  4 Jun 2015 14:06:03 -0600
Based on a report by Michael Felt, via Paul Eggert on the
coreutils list.

* doc/autoconf.texi (Limitations of Builtins) <for>: Document
problem with 'for var in ;'.

Signed-off-by: Eric Blake <eblake <at> redhat.com>
---
 doc/autoconf.texi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 8c4302d..bbc9fa3 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -17757,6 +17757,40 @@ Limitations of Builtins
 word splitting on @samp{$@{1+"$@@"@}}; see @ref{Shell Substitutions},
 item @samp{$@@}, for more.

+Posix requires support for a @command{for} loop with no list after
+@code{in}.  However, Solaris @command{/bin/sh} treats that as a syntax
+error.  It is possible to work around this by providing any shell word
+that expands to nothing, or by ignoring an obvious sentinel.
+
+@example
+$ @kbd{/bin/sh -c 'for a in $empty; do echo hi; done'}
+$ @kbd{/bin/sh -c 'for a in ; do echo hi; done'}
+/bin/sh: syntax error at line 1: `;' unexpected
+@end example
+
+The problem is most common in makefile fragments where a make variable
+is used as the source of a list, but sometimes results in no text.  In
+that context, another common workaround is to use a shell variable
+rather than a make variable as the source of the list.
+
+@example
+$ @kbd{cat Makefile}
+list =
+bad:
+	@@for arg in $(list); do echo $$arg; done
+good:
+	@@list='$(list)'; for arg in $$list; do echo $$arg; done
+$ @kbd{make bad list='a b'}
+a
+b
+$ @kbd{make bad 2&>1 | head -n1}
+sh: syntax error at line 1: `;' unexpected
+$ @kbd{make good}
+$ @kbd{make good list='a b'}
+a
+b
+@end example
+
 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 those tokens:
-- 
2.4.2





This bug report was last modified 10 years and 48 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.