bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test evaluation


From: Chet Ramey
Subject: Re: test evaluation
Date: Mon, 24 Sep 2001 13:53:43 -0400

> bash version: 2.05-4 (debian)
> GNU bash, version 2.05.0(1)-release (i386-pc-linux-gnu)
> 
> Description:
> Here are some interesting test evaluations:
> 
> Repeat-By:
> > f="="
> > [ -f "$f" -a -r "$f" ] && echo ok
> [: too many arguments
> 
> > [  -f =  ] && echo ok
> ok
> (Works as expected)
> 
> > [  -f = -a -r = ] && echo ok
> [: too many arguments
> 
> > [ \( -f = \) -a \( -r = \) ] && echo ok
> [: `)' expected, found ]
> (Errm...? ;)
> 
> Looks like parsing bugs in bash/test...

`test' specifies an inherently ambiguous grammar.  POSIX.2 tried to fix
this by specifying the behavior of `test' when given up to four operands
(well, four operands as long as the first is `!').  POSIX recommends
using the shell's conditional operators to replace more complicated tests,
especially those involving `-a' and `-o'.

When presented with four or more operands, bash treats binary operators
as having higher precedence than unary operators, which is the opposite
of what you seem to want.  With that in mind, the bash behavior should
be obvious.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]