tags 426990 - moreinfo
tags 426990 + upstream
# documentation bug
severity 426990 minor
retitle 426990 bash: "help test" gives no hint of complicated precedence rules
quit

OZAKI Masanobu wrote:
> On Fri, 2010-11-05 at 03:17:13 -0500, Jonathan Nieder <jrnie...@gmail.com> 
> wrote:

>>> Please try
>>>   % bash -c 'test ! -a . && echo true'
>>> and compare with the result of
>>>   % bash -c '/usr/bin/test ! -a . && echo true'
>>
>> So which one is right?
>
> Both should echo "true", but the former did not: I found that the former
> sometimes returns the correct result, but have not found what makes the
> difference.

Thanks.  The second one doesn't echo "true", does it?

Summarizing: There are two -a operators: a unary one and a binary one.
This results in reduce/reduce conflicts when parsing a "test" expression.

"help test" says:

        See the bash manual page bash(1) for the handling of
        parameters (i.e., missing parameters).

which does not really tempt me to look at the manual.  bash(1) says:

        Expressions may be combined using the following
        operators, listed in decreasing order of precedence.

giving an order of precedence with ! before -a.  Then it quickly
corrects itself:

        test and [ evaluate conditional expressions using a set
        of rules based on the number of arguments.

                0 arguments
                        The expression is false.
[...]
                3 arguments
                        If the second argument is one of the
                        binary conditional operators listed above
                        under CONDITIONAL EXPRESSIONS, the result
                        of the expression is the result of the
                        binary test using the first and third
                        arguments as operands.  The -a and -o
                        operators are considered binary operators
                        when there are three arguments.

That answers the question.  Unfortunately, the next sentence is
inconsistent with that answer:

                                                         If the first
                        argument is !, the value is the negation of
                        the two-argument test using the second and
                        third arguments.

Suggested changes:

 1. Change the parenthesis in "help bash" to something like
    "(e.g., operator precedence and missing parameters)".

 2. Change the second paragraph in the description in bash(1) of
    the test builtin to something like

        Expressions may be combined using the following operators.
        The evaluation depends on the number of arguments; see below.
        When 5 or more arguments are present, this list is in
        decreasing order of precedence.

 3. Add the word "Otherwise," before "If the first argument is !" in
    the 3-argument case.

Thoughts?  I can try writing a patch if this looks like a good idea.



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to