[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash accepts script with incorrect syntax and goes into infinite loo
From: |
Pierre Gaston |
Subject: |
Re: bash accepts script with incorrect syntax and goes into infinite loop |
Date: |
Fri, 9 Oct 2009 13:31:43 +0300 |
On Fri, Oct 9, 2009 at 1:24 PM, Dave B <dave_br@gmx.com> wrote:
> On Friday 09 October 2009, Pierre Gaston wrote:
>
> > > Repeat-By:
> > > printf '%s\n%s\n' foo bar | while read NAME;
> > > echo NAME=$NAME
> > > do
> > > echo blah
> > > done
> >
> > Not sure what is the incorrect syntax, and it seems normal that it goes
> > into an infinite loop since echo is always true.
>
> Well, it seems to me (and as stated in the bug report) that a "do" should
> follow the "while read NAME;".
>
>
the while syntax is like this:
"while list; do list; done"
and the manual says "A sequence of one or more newlines may appear in a
list instead of a semicolon to delimit commands."
so you can have:
while command
command
do
(the ; in the definition is probably there to keep the definition on one
line, you can replace the ; in all the other definitions by a newline like:
if command
then
This also works the same way in the other shells. For me it's not a bug.