cvs commit: src/bin/test test.1

Yar Tikhiy yar at comp.chem.msu.su
Thu Jul 27 20:34:07 UTC 2006


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


More information about the cvs-src mailing list