#469233 bash man page: confusion between commands and pipelines, associativity undefined

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Vincent Lefevre
Date:
2024-07-01 00:03:03 UTC
Severity:
minor
#469233#5
Date:
2008-03-04 00:57:50 UTC
From:
To:
In the SHELL GRAMMAR section, the bash man page first describes
(simple) commands and pipeplines, then lists:

   A list is a sequence of one or more pipelines separated by one of
                                       ^^^^^^^^^
   the operators ;, &, &&, or ||, and optionally terminated  by  one
   of ;, &, or <newline>.

but a few lines later, it talks about commands instead of pipelines:

   [...] An AND list has the form

          command1 && command2

   command2  is  executed  if, and only if, command1 returns an exit
   status of zero.

   An OR list has the form

          command1 || command2

   command2 is executed if and only if command1 returns  a  non-zero
   exit  status.   The return status of AND and OR lists is the exit
   status of the last command executed in the list.

Also, though the man page says that && and || have equal precedence,
it doesn't say which associativity. For instance, is it

    (1)  list && pipeline

or

    (2)  pipeline && list

? For instance, in

    pipeline1 || pipeline2 && pipeline3

where pipeline1 returns 0 (true) and pipeline2 returns 1 (false):

Case 1: list "pipeline1 || pipeline2" is executed. As pipeline1 is
true, pipeline2 is not executed. And as the list is true, pipeline3
is executed.

Case 2: pipeline1 is executed, and as it is true, the list
"pipeline2 && pipeline3" is not executed, i.e. neither pipeline2,
nor pipeline3.

It seems to be Case 1 (left associative):

$ true || false && echo case1
case1

So, I suppose that the above should be replaced by:

   [...] An AND list has the form

          list && pipeline

   pipeline is executed if and only if list returns an exit status of
   zero.

   An OR list has the form

          list || pipeline

   pipeline is executed if and only if list returns a non-zero exit
   status. The return status of AND and OR lists is the exit status
   of the last pipeline executed in the list.