Re: select syntax violates the POLA

2021-04-04 Thread Oğuz
5 Nisan 2021 Pazartesi tarihinde konsolebox  yazdı:
>
> The manual itself may be lacking in some places but the syntax here is
> explicit. There's no reason to follow otherwise. These "other methods"
> can only be an implementation mistake or a compromise that's not
> exactly a supported functionality or feature. This case where () and
> {} are allowed to not end with semicolon before 'else' when others
> aren't is likely one.


These all work (as expected) on the development branch:

bash-5.1$ if : ; then case _ in esac else : ; fi
bash-5.1$ if : ; then for _ do : ; done else : ; fi
bash-5.1$ if : ; then [[ _ ]] else : ; fi
bash-5.1$ if : ; then (( 0 )) else : ; fi
bash-5.1$ if { : ; } then while { : ; } do break ; done else : ; fi
bash-5.1$

If they didn't that'd be a defect in the shell, POSIX allows these
constructs, and it also makes sense that a list separator is optional
between else and the preceding command when that command is terminated with
a reserved word.


> > and the ';' there is just an
> > indication that something must ensure that the word that follows is
> > correctly interpreted as a reserved word (when one is required).
>
> Then why does it not work with other keywords that begin a block?


It does work with then, do, elif, else, done, esac, and }.


-- 
Oğuz


Re: select syntax violates the POLA

2021-04-04 Thread konsolebox
On Sat, Apr 3, 2021 at 1:09 AM Robert Elz  wrote:
>   |  [[ ]] and (( )) are a form of reserved words themselves
>
> Those are bash specials, and I am fairly sure that (( and )) will be
> operators, not reserved words (they cannot really be the latter, as ( and
> ) are operators) and I suspect that [[ and ]] might be as well, but there
> I'm not sure.   operators and reserved words are quite different things.
> Operators (unquoted) are recognised as themselves wherever they appear.

Stop suspecting and read the source code.  Look at parse.y starting at
line 2150.  They are labeled as "Reserved words".


-- 
konsolebox



Re: select syntax violates the POLA

2021-04-04 Thread konsolebox
On Mon, Apr 5, 2021 at 12:46 PM Robert Elz  wrote:
>
> Date:Sun, 04 Apr 2021 20:27:15 -0400
> From:wor...@alum.mit.edu (Dale R. Worley)
> Message-ID:  <87wntha84c@hobgoblin.ariadne.com>
>
>
>   | The manual page says
>   |
>   |if list; then list; [ elif list; then list; ] ... [ else list; ] fi
>   |
>   | so clearly there should be a ; or newline before the list in the
>   | else-clause.
>
> You're assuming that the manual is a precise specification of what
> is allowed.  It isn't.  At least in this case it shows something that
> works, so if you write an if statement that way, it will function.
> That does not imply that there are not other methods.

The manual itself may be lacking in some places but the syntax here is
explicit. There's no reason to follow otherwise. These "other methods"
can only be an implementation mistake or a compromise that's not
exactly a supported functionality or feature. This case where () and
{} are allowed to not end with semicolon before 'else' when others
aren't is likely one.

> and the ';' there is just an
> indication that something must ensure that the word that follows is
> correctly interpreted as a reserved word (when one is required).

Then why does it not work with other keywords that begin a block?  The
enclosure of {} and () should make semicolons optional for parsing
with them as well.  This should have been explicitly allowed by the
shell.  It's highly doable even if they are followed with
non-keywords.  Just look at awk's syntax.



--
konsolebox



Re: select syntax violates the POLA

2021-04-04 Thread Robert Elz
Date:Sun, 04 Apr 2021 20:27:15 -0400
From:wor...@alum.mit.edu (Dale R. Worley)
Message-ID:  <87wntha84c@hobgoblin.ariadne.com>


  | The manual page says
  |
  |if list; then list; [ elif list; then list; ] ... [ else list; ] fi
  |
  | so clearly there should be a ; or newline before the list in the
  | else-clause.

You're assuming that the manual is a precise specification of what
is allowed.  It isn't.  At least in this case it shows something that
works, so if you write an if statement that way, it will function.
That does not imply that there are not other methods.

In general, when reading the bash man page, anywhere it says "list;"
(except apparently in select statements) you should read that as meaning
the same as the POSIX compound_list, and the ';' there is just an
indication that something must ensure that the word that follows is
correctly interpreted as a reserved word (when one is required).  A ';'
will do that.   So do other things.

kre

ps: you can also use '&' in place of ';' or newline, when a separator
is required.   Though that gives the preceding command a different
operational behaviour of course.




Re: select syntax violates the POLA

2021-04-04 Thread Dale R. Worley
Robert Elz  writes:
> From:wor...@alum.mit.edu (Dale R. Worley)
>
>   | I was going to ask why "else {" works,
>
> The right question would be why '} else' works.

Yeah, typo on my part.  The manual page says

   if list; then list; [ elif list; then list; ] ... [ else list; ] fi

so clearly there should be a ; or newline before the list in the
else-clause.  But the grammar doesn't seem to enforce that:

if_clause  : If compound_list Then compound_list else_part Fi

I'm sure that the real answer involves decrypting the logic inside Bash
that turns on recognition of reserved words, and that must be more
complicated than the rule in the manual page.

Dale