From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 5 15:08:23 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2F62716A401 for ; Thu, 5 Apr 2007 15:08:23 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.freebsd.org (Postfix) with ESMTP id D9DF613C480 for ; Thu, 5 Apr 2007 15:08:12 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan@localhost [127.0.0.1]) by dan.emsphone.com (8.14.0/8.13.8) with ESMTP id l35F86rw040129 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 5 Apr 2007 10:08:06 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.0/8.14.0/Submit) id l35F864Y040119; Thu, 5 Apr 2007 10:08:06 -0500 (CDT) (envelope-from dan) Date: Thu, 5 Apr 2007 10:08:06 -0500 From: Dan Nelson To: Joe Marcus Clarke Message-ID: <20070405150806.GD45237@dan.emsphone.com> References: <1175757140.67579.50.camel@shumai.marcuscom.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1175757140.67579.50.camel@shumai.marcuscom.com> X-OS: FreeBSD 6.2-STABLE User-Agent: Mutt/1.5.14 (2007-02-12) Cc: freebsd-hackers@freebsd.org Subject: Re: Problem with test(1) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2007 15:08:23 -0000 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. > http://www.marcuscom.com/downloads/test.c.diff -- Dan Nelson dnelson@allantgroup.com