From owner-cvs-all@FreeBSD.ORG Thu Jul 27 20:34:07 2006 Return-Path: X-Original-To: cvs-all@freebsd.org Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D8A2C16A4DF; Thu, 27 Jul 2006 20:33:56 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2F1AE43D53; Thu, 27 Jul 2006 20:33:44 +0000 (GMT) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.4/8.13.3) with ESMTP id k6RKXY08008577; Fri, 28 Jul 2006 00:33:34 +0400 (MSD) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.4/8.13.3/Submit) id k6RKXYWx008572; Fri, 28 Jul 2006 00:33:34 +0400 (MSD) (envelope-from yar) Date: Fri, 28 Jul 2006 00:33:33 +0400 From: Yar Tikhiy To: John Baldwin Message-ID: <20060727203333.GE5075@comp.chem.msu.su> References: <200607271908.k6RJ8Los011463@repoman.freebsd.org> <200607271534.58605.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200607271534.58605.jhb@freebsd.org> User-Agent: Mutt/1.5.9i 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-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jul 2006 20:34:07 -0000 On Thu, Jul 27, 2006 at 03:34:57PM -0400, John Baldwin wrote: > 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. Thank you for the lecture on the shell, but I must be missing something entirely different. %ktrace /bin/test -e /frotz -a -e /kikimor %kdump | egrep -B1 frotz\|kikimor 2276 test CALL stat(0xbfbfed81,0xbfbfeb50) 2276 test NAMI "/frotz" -- 2276 test CALL stat(0xbfbfed8e,0xbfbfeb40) 2276 test NAMI "/kikimor" %ls /frotz /kikimor ls: /frotz: No such file or directory ls: /kikimor: No such file or directory -- Yar