Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16732

Re: Undocumented for-loop construct

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Undocumented for-loop construct
Date 2020-08-07 09:36 -0400
Organization ITS, Case Western Reserve University
Message-ID <mailman.1134.1596807401.2739.bug-bash@gnu.org> (permalink)
References <87364zur1p.fsf@hobgoblin.ariadne.com> <78fdbb4c-c532-cbdc-60cd-cc6937b7e657@case.edu>

Show all headers | View raw


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/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Undocumented for-loop construct Chet Ramey <chet.ramey@case.edu> - 2020-08-07 09:36 -0400

csiph-web