[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Undocumented for-loop construct
From: |
Chet Ramey |
Subject: |
Re: Undocumented for-loop construct |
Date: |
Fri, 7 Aug 2020 09:36:30 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 |
On 8/6/20 10:29 PM, Dale R. Worley wrote:
> Klaas Vantournhout <klaas.vantournhout@gmail.com> writes:
>> Recently I came across a surprising undocumented bash-feature
>>
>> $ for i in 1 2 3; { echo $i; };
>>
>> The usage of curly-braces instead of the well-documented do ... done
>> construct was a complete surprise to me and even lead me to open the
>> following question on stack overflow:
>
> Interesting! Looking at parse.y, it looks like do ... done can be
> replaced with { ... } in 'for' and 'select' statements, but not 'while'
> and 'until' statements.
The `select' syntax is enough like `for' -- practically identical from a
grammar perspective -- that it made sense to support it in `select'. The
fact that the Korn shell supports braces in `select' made it a
compatibility issue as well.
Not clear why that would be, though I haven't
> tried extending while/until and recompiling parse.y; maybe it doesn't
> work.
Because there's a difference between a `list' (for and select) and a
`command list' (while and until). If you don't want ambiguous constructs,
you nee a reserved word to separate the test command from the body
command.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/