[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#20733: [PATCH] doc: mention 'for' syntax issue on older shells
From: |
Eric Blake |
Subject: |
bug#20733: [PATCH] doc: mention 'for' syntax issue on older shells |
Date: |
Thu, 04 Jun 2015 14:59:28 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
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
signature.asc
Description: OpenPGP digital signature
bug#20733: coreutils build problem, Andreas Schwab, 2015/06/04
bug#20733: [PATCH] doc: mention 'for' syntax issue on older shells, Eric Blake, 2015/06/04
Message not available