Package: bash
Version: 3.1dfsg-9
Severity: minor

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.

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.24.3-20080226 (SMP w/2 CPU cores; PREEMPT)
Locale: LANG=POSIX, LC_CTYPE=en_US.ISO8859-1 (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash

Versions of packages bash depends on:
ii  base-files                4.0.2          Debian base system miscellaneous f
ii  debianutils               2.28.4         Miscellaneous utilities specific t
ii  libc6                     2.7-9          GNU C Library: Shared libraries
ii  libncurses5               5.6+20080203-1 Shared libraries for terminal hand

Versions of packages bash recommends:
pn  bash-completion               <none>     (no description available)

-- no debconf information



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to