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


Message #43 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: Re: bug#20733: [PATCH] doc: mention 'for' syntax issue on older shells
Date: Fri, 5 Jun 2015 09:35:37 +0100
2015-06-04 16:32:48 -0600, Eric Blake:
> On 06/04/2015 02:59 PM, Eric Blake wrote:
> 
> >>> +good:
> >>> +	@@list='$(list)'; for arg in $$list; do echo $$arg; done
> >> [...]
> >>
> >> Another option is to use:
> >>
> >>    for arg in $${-+$(list)}; do echo $$arg; done
> 
> > Furthermore, your suggestion mishandles a list with a bare }, whereas
> > mine does not.  "make good list='} a'" should output $'}\na\n', not $'a}\n'.
> 
> Of course, your version has the benefit of preserving a list that
> contains shell quoting (such as list = "a  b" intended to produce a
> single string $'a  b')
[...]

Not with all sh implementations though. With sh based on earlier
versions of zsh (like the sh of some old OS/X), $${-+$(list)}
would undergo split+glob.

As a solution that minimises the difference from for i in
$(list),

   for i in $$empty $(list); do...

   for i in `` $(list)

As already pointed out would be better.

See also:

   set x $(list); shift; for i do echo "$$i"; done

Which is Bourne and POSIX (though according to
http://www.in-ulm.de/~mascheck/various/bourne_args/ not
supported by early versions of the Almquist shell (possibly
still found in the wild in some Minix systems).

-- 
Stephane





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.