Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Short loops?



Bart Schaefer wrote:
> The doc ought to get changed, then.  The two entries for `while' (and
> similarly for all the "short" variants) read:
>
> `while LIST do LIST done'
> `while LIST { LIST }'
>
> The first and second uses of LIST both require either a newline or a
> trailing semicolon; the fourth use of LIST may have a newline or a
> semicolon or not, without affecting the result; and the third use
> requires not only that there NOT be a newline or semicolon, but also
> that the list ends with a [[ ]] (( )) ( ) or { } construct.

No.  No one of the above four LIST require any trailing semicolons or
newlines.  As decribed in the manual, reserved words like do, done, { are
only recognized in command position.  If you write while true { ... } then
{ is not in command position, it is simply an argument to true.  Words are
in command position after a newline or a semicolon or after )) or ]] or
after do, then, {, } etc.  Zsh has to know that { is not a simple argument
to a command, but a reserved word.  The { echo } case works and seems to be
an exception to this rule but is really a pathologic special case handled
explicitely in lex.c and it only works if ignorebraces is not set.  This
syntax worked in bash-1.14 but it no longer works in bash-2.0 because it
violates POSIX.  When ignorebraces is set (e.g. in sh mode) the following
is perfectly valid:

while true { echo foo }
do
        ...
done

Here true is invoked with four arguments: {, echo, foo and }.

Zoltan



Messages sorted by: Reverse Date, Date, Thread, Author