bug-coreutils
[Top][All Lists]
Advanced

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

bug#20733: [PATCH] doc: mention 'for' syntax issue on older shells


From: Stephane Chazelas
Subject: bug#20733: [PATCH] doc: mention 'for' syntax issue on older shells
Date: Fri, 5 Jun 2015 09:35:37 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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

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