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




Reply via email to