From owner-cvs-src@FreeBSD.ORG  Thu Jul 27 19:35:09 2006
Return-Path: <owner-cvs-src@FreeBSD.ORG>
X-Original-To: cvs-src@freebsd.org
Delivered-To: cvs-src@freebsd.org
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id EC42F16A4DE;
	Thu, 27 Jul 2006 19:35:09 +0000 (UTC) (envelope-from jhb@freebsd.org)
Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net
	[66.23.211.162])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 540D843D72;
	Thu, 27 Jul 2006 19:35:03 +0000 (GMT) (envelope-from jhb@freebsd.org)
Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1])
	(authenticated bits=0)
	by server.baldwin.cx (8.13.4/8.13.4) with ESMTP id k6RJZ2GY079948;
	Thu, 27 Jul 2006 15:35:02 -0400 (EDT) (envelope-from jhb@freebsd.org)
From: John Baldwin <jhb@freebsd.org>
To: Yar Tikhiy <yar@freebsd.org>
Date: Thu, 27 Jul 2006 15:34:57 -0400
User-Agent: KMail/1.9.1
References: <200607271908.k6RJ8Los011463@repoman.freebsd.org>
In-Reply-To: <200607271908.k6RJ8Los011463@repoman.freebsd.org>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200607271534.58605.jhb@freebsd.org>
X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by
	milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]);
	Thu, 27 Jul 2006 15:35:03 -0400 (EDT)
X-Virus-Scanned: ClamAV 0.87.1/1624/Thu Jul 27 13:11:25 2006 on
	server.baldwin.cx
X-Virus-Status: Clean
X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 
	autolearn=ham version=3.1.0
X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on server.baldwin.cx
Cc: cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org
Subject: Re: cvs commit: src/bin/test test.1
X-BeenThere: cvs-src@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: CVS commit messages for the src tree <cvs-src.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/cvs-src>,
	<mailto:cvs-src-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/cvs-src>
List-Post: <mailto:cvs-src@freebsd.org>
List-Help: <mailto:cvs-src-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/cvs-src>,
	<mailto:cvs-src-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 27 Jul 2006 19:35:10 -0000

On Thursday 27 July 2006 15:08, Yar Tikhiy wrote:
> yar         2006-07-27 19:08:21 UTC
> 
>   FreeBSD src repository
> 
>   Modified files:
>     bin/test             test.1 
>   Log:
>   Document that both sides of -a or -o are always evaluated.  This
>   "feature" doesn't seem to be in the standards or elsewhere, and
>   it is against what we are used to in C and sh(1), so put the
>   paragraph under BUGS.
>   
>   Pointed out by: dougb
>   MFC after:      3 days

This isn't a bug, it's the only way it can work.  What you are missing is that 
the shell has to evaluate the arguments and then pass them to test(1).  Thus, 
when you do:

if [ foo ] && [ bar ]; then
	...
fi

The shell runs evaluates all of '[ foo ]' as needed and runs it.  It then 
decides whether to evaluate and run '[ bar ]' after the first command runs.  
When you do:

if [ foo -a bar ]; then
	...
fi

The shell has to evaluate all of '[ foo -a bar ]' and run the single command 
and make the decision based on what it returns.

I don't think this is really a bug, it's more the fact of realizing that even 
if [ maybe optimized to be a built-in, when you are using it, you have to 
treat it as the shell executing a separate program, just as you would expect:

if grep -q ${FOO} < ${BAR}; then
	...
fi

To evaluate both ${FOO} and ${BAR} before running grep.

-- 
John Baldwin