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

From: Eric Blake <[email-masked]>
Date: Thu, 04 Jun 2015 14:59:28 -0600

On 06/04/2015 02:36 PM, Stephane Chazelas wrote:
> 2015-06-04 14:06:03 -0600, Eric Blake:
> [...]
>> +$ @kbd{cat Makefile}
>> +list =
>> +bad:
>> +	@@for arg in $(list); do echo $$arg; done
>> +good:
>> +	@@list='$(list)'; for arg in $$list; do echo $$arg; done
> [...]
> 
> Another option is to use:
> 
>    for arg in $${-+$(list)}; do echo $$arg; done
> 
> 
> That's ${var+value} that expands to value if var is set. $- is
> always set. $0 could also be used instead.

Also could use $$, $? (except $? doesn't always start life set if probed
as the first thing in some shells), $# (except some shells confuse
${varOPvalue} vs. ${#var} when # is used as var). But from a readability
perspective, I don't think that playing golf for the shortest construct
is helpful, when compared to demonstrating something that is more
commonly seen in practice.

Furthermore, your suggestion mishandles a list with a bare }, whereas
mine does not.  "make good list='} a'" should output $'}\na\n', not $'a}\n'.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org