Problem with test(1)

Joe Marcus Clarke marcus at FreeBSD.org
Fri Apr 6 15:41:00 UTC 2007


On Thu, 2007-04-05 at 10:08 -0500, Dan Nelson wrote:
> In the last episode (Apr 05), Joe Marcus Clarke said:
> > I noticed something weird with test(1) when I ran across a problem port
> > Makefile.  Our test(1) doesn't properly check to make sure there is an
> > operand argument to unary operators like -f.  For example:
> > 
> > test -f
> > 
> > Will print "TRUE" on FreeBSD.  On Solaris, it will die:
> > 
> > /usr/bin/test[8]: test: argument expected
> > 
> > I think this patch is correct in that it does fix the problem, and the
> > TEST.sh and TEST.csh regression scripts report the same results pre and
> > post-patch.  Comments?
> 
> If you follow POSIX's description of test, FreeBSD's current behaviour
> is valid and Solaris isn't:
> 
>   http://www.opengroup.org/onlinepubs/009695399/utilities/test.html
> 
>   The algorithm for determining the precedence of the operators and the
>   return value that shall be generated is based on the number of
>   arguments presented to test. (However, when using the "[...]" form,
>   the right-bracket final argument shall not be counted in this
>   algorithm.)
> 
>   In the following list, $1, $2, $3, and $4 represent the arguments
>   presented to test:
> 
>   0 arguments:
>       Exit false (1).
>   1 argument:
>       Exit true (0) if $1 is not null; otherwise, exit false.
>   ...
> 
> Unary operators shouldn't get parsed as such unless there are two
> arguments.

Thanks for the clarification.  Solaris' test(1) man page has the same
excerpt yet all of their implementations of test(1) require the argument
to the operator.  This confused me since the man page also claims that
their test(1) is compliant with recent Open Group standards.

Joe

-- 
Joe Marcus Clarke
FreeBSD GNOME Team      ::      gnome at FreeBSD.org
FreeNode / #freebsd-gnome
http://www.FreeBSD.org/gnome
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20070406/9a44cbf8/attachment.pgp


More information about the freebsd-hackers mailing list