GNU bug report logs - #22216
test, expr Operator Precedence and Associativity

Previous Next

Package: coreutils;

Reported by: Dan Jacobson <jidanni <at> jidanni.org>

Date: Mon, 21 Dec 2015 17:19:01 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22216 in the body.
You can then email your comments to 22216 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#22216; Package coreutils. (Mon, 21 Dec 2015 17:19:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dan Jacobson <jidanni <at> jidanni.org>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 21 Dec 2015 17:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dan Jacobson <jidanni <at> jidanni.org>
To: bug-coreutils <at> gnu.org
Subject: test, expr Operator Precedence and Associativity
Date: Tue, 22 Dec 2015 01:18:23 +0800
$ man perlop # has a 50 line section called
   Operator Precedence and Associativity

Might (info "(coreutils) test invocation") not fully specify test's?
Might (info "(coreutils) expr invocation") not fully specify expr's?




Reply sent to Pádraig Brady <P <at> draigBrady.com>:
You have taken responsibility. (Mon, 21 Dec 2015 18:01:02 GMT) Full text and rfc822 format available.

Notification sent to Dan Jacobson <jidanni <at> jidanni.org>:
bug acknowledged by developer. (Mon, 21 Dec 2015 18:01:02 GMT) Full text and rfc822 format available.

Message #10 received at 22216-done <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Dan Jacobson <jidanni <at> jidanni.org>, 22216-done <at> debbugs.gnu.org
Subject: Re: bug#22216: test, expr Operator Precedence and Associativity
Date: Mon, 21 Dec 2015 18:00:42 +0000
On 21/12/15 17:18, Dan Jacobson wrote:
> $ man perlop # has a 50 line section called
>    Operator Precedence and Associativity
> 
> Might (info "(coreutils) test invocation") not fully specify test's?
> Might (info "(coreutils) expr invocation") not fully specify expr's?

expr precedence is quite well described I think.
How about this for test(1):

commit fd92e4f9c0c7465472660948008879e7e6df1de8
Author: Pádraig Brady <P <at> draigBrady.com>
Date:   Mon Dec 21 17:57:30 2015 +0000

    doc: describe test operator precedence and associativity

    * doc/coreutils.texi (Connectives for test): Add notes
    on precedence and associativity.
    Fixes http://bugs.gnu.org/22216

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 33be4d8..9fffc82 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -12645,18 +12645,23 @@ The usual logical connectives.
 @item ! @var{expr}
 @opindex !
 True if @var{expr} is false.
+@samp{!} has lower precedence than
+all components of @var{expr}.

 @item @var{expr1} -a @var{expr2}
 @opindex -a
 @cindex logical and operator
 @cindex and operator
 True if both @var{expr1} and @var{expr2} are true.
+@samp{-a} is left associative,
+and has a higher precedence than @samp{-o}.

 @item @var{expr1} -o @var{expr2}
 @opindex -o
 @cindex logical or operator
 @cindex or operator
 True if either @var{expr1} or @var{expr2} is true.
+@samp{-o} is left associative.

 @end table






Information forwarded to bug-coreutils <at> gnu.org:
bug#22216; Package coreutils. (Tue, 22 Dec 2015 00:01:02 GMT) Full text and rfc822 format available.

Message #13 received at 22216-done <at> debbugs.gnu.org (full text, mbox):

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 22216-done <at> debbugs.gnu.org
Subject: Re: bug#22216: test, expr Operator Precedence and Associativity
Date: Tue, 22 Dec 2015 08:00:25 +0800
OK. Also make sure (info "(coreutils) test invocation") makes it clear that
one cannot use
test -f $1 -a $1 ! -ot $2 #and must use
test -f $1 -a ! $1 -ot $2 #.




Information forwarded to bug-coreutils <at> gnu.org:
bug#22216; Package coreutils. (Tue, 22 Dec 2015 00:06:01 GMT) Full text and rfc822 format available.

Message #16 received at 22216-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>,
 Pádraig Brady <P <at> draigBrady.com>
Cc: 22216-done <at> debbugs.gnu.org
Subject: Re: bug#22216: test, expr Operator Precedence and Associativity
Date: Mon, 21 Dec 2015 17:05:09 -0700
[Message part 1 (text/plain, inline)]
On 12/21/2015 05:00 PM, 積丹尼 Dan Jacobson wrote:
> OK. Also make sure (info "(coreutils) test invocation") makes it clear that
> one cannot use
> test -f $1 -a $1 ! -ot $2 #and must use
> test -f $1 -a ! $1 -ot $2 #.

Use of -a in test is inherently non-portable.  POSIX even says so -
there are some expressions which are completely ambiguous when you
attempt to use -a or -o.

Also, your lack of quoting is a classic pitfall for how to incorrectly
use test.

Better than what you typed would be using:

test -f "$1" && test ! "$1" -ot "$2"

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#22216; Package coreutils. (Tue, 22 Dec 2015 00:22:01 GMT) Full text and rfc822 format available.

Message #19 received at 22216-done <at> debbugs.gnu.org (full text, mbox):

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: Eric Blake <eblake <at> redhat.com>
Cc: 22216-done <at> debbugs.gnu.org,
 Pádraig Brady <P <at> draigBrady.com>
Subject: Re: bug#22216: test, expr Operator Precedence and Associativity
Date: Tue, 22 Dec 2015 08:21:16 +0800
>>>>> "EB" == Eric Blake <eblake <at> redhat.com> writes:

EB> On 12/21/2015 05:00 PM, 積丹尼 Dan Jacobson wrote:
>> OK. Also make sure (info "(coreutils) test invocation") makes it clear that
>> one cannot use
>> test -f $1 -a $1 ! -ot $2 #and must use
>> test -f $1 -a ! $1 -ot $2 #.

EB> Use of -a in test is inherently non-portable.  POSIX even says so -
EB> there are some expressions which are completely ambiguous when you
EB> attempt to use -a or -o.

Mmmm! The documentation should mention that!

EB> Also, your lack of quoting is a classic pitfall for how to incorrectly
EB> use test.

EB> Better than what you typed would be using:

EB> test -f "$1" && test ! "$1" -ot "$2"

Mmmm, quote tips only mention in the case of (info "(coreutils) String tests").
Maybe need to mention in more places!

Also no "X$1" = X special tip seen...




Information forwarded to bug-coreutils <at> gnu.org:
bug#22216; Package coreutils. (Tue, 22 Dec 2015 01:31:02 GMT) Full text and rfc822 format available.

Message #22 received at 22216 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>,
 Eric Blake <eblake <at> redhat.com>
Cc: 22216 <at> debbugs.gnu.org
Subject: Re: bug#22216: test, expr Operator Precedence and Associativity
Date: Tue, 22 Dec 2015 01:30:24 +0000
[Message part 1 (text/plain, inline)]
On 22/12/15 00:21, 積丹尼 Dan Jacobson wrote:
>>>>>> "EB" == Eric Blake <eblake <at> redhat.com> writes:
> 
> EB> On 12/21/2015 05:00 PM, 積丹尼 Dan Jacobson wrote:
>>> OK. Also make sure (info "(coreutils) test invocation") makes it clear that
>>> one cannot use
>>> test -f $1 -a $1 ! -ot $2 #and must use
>>> test -f $1 -a ! $1 -ot $2 #.
> 
> EB> Use of -a in test is inherently non-portable.  POSIX even says so -
> EB> there are some expressions which are completely ambiguous when you
> EB> attempt to use -a or -o.
> 
> Mmmm! The documentation should mention that!
> 
> EB> Also, your lack of quoting is a classic pitfall for how to incorrectly
> EB> use test.
> 
> EB> Better than what you typed would be using:
> 
> EB> test -f "$1" && test ! "$1" -ot "$2"
> 
> Mmmm, quote tips only mention in the case of (info "(coreutils) String tests").
> Maybe need to mention in more places!

Patch V2 attached.

thanks,
Pádraig

[doc-test-logical-ops.patch (text/x-patch, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#22216; Package coreutils. (Tue, 22 Dec 2015 02:09:02 GMT) Full text and rfc822 format available.

Message #25 received at 22216 <at> debbugs.gnu.org (full text, mbox):

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 22216 <at> debbugs.gnu.org, Eric Blake <eblake <at> redhat.com>
Subject: Re: bug#22216: test, expr Operator Precedence and Associativity
Date: Tue, 22 Dec 2015 10:08:20 +0800
>>>>> "PB" == Pádraig Brady <P <at> draigBrady.com> writes:

PB> +Also @samp{!} is a shell special character and needs to be quoted.

Perhaps say instead:

Also @samp{!} is often a shell special character and is best used quoted.






bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 19 Jan 2016 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 111 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.