Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jul 2006 00:33:33 +0400
From:      Yar Tikhiy <yar@comp.chem.msu.su>
To:        John Baldwin <jhb@freebsd.org>
Cc:        cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org
Subject:   Re: cvs commit: src/bin/test test.1
Message-ID:  <20060727203333.GE5075@comp.chem.msu.su>
In-Reply-To: <200607271534.58605.jhb@freebsd.org>
References:  <200607271908.k6RJ8Los011463@repoman.freebsd.org> <200607271534.58605.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060727203333.GE5075>