help-bash
[Top][All Lists]
Advanced

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

Re: Question about compound_list in bash grammar


From: Chet Ramey
Subject: Re: Question about compound_list in bash grammar
Date: Wed, 9 Dec 2020 15:03:20 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.5.1

On 12/9/20 1:18 PM, crimson flame wrote:
Hi,
Why does the following command not work on bash CLI?

*for i in {1..5}; do echo $i done*

Because `done' has to follow an operator to be recognized as a reserved
word. It's perfectly valid to have something like

for i in {1..5}; do echo $i done done done done ; done

That's not done completely in the grammar: the grammar works with the tokens the lexical analyzer provides. The lexical analyzer keeps track
of the previous tokens it recognizes and returns DONE (the reserved
word) only if the previous token allows it.

Two of those previous tokens happen to be `;' and newline, but you can
also end the compound_list with, say, `&'.

--
``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/



reply via email to

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