Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-amd64
Navigation:
Lists: gentoo-amd64: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-amd64@g.o
From: Richard Freeman <rich0@g.o>
Subject: Re: How to use &&
Date: Sun, 04 Jan 2009 10:57:28 -0500
Maciej Kazulak wrote:
> That's how bash evaluates logic expressions. There's even a fancy word 
> for it i think. Point is it will execute commands only to the point 
> where it can determine the logic result. 

The fancy word for it would probably be short circuit evaluation:

http://en.wikipedia.org/wiki/Short-circuit_evaluation

When placing code in a boolean expression it is critical to understand 
whether the boolean operator will be evaluated in a short-circuit 
fashion in any language.

I'm not aware of any language that works this way, but potentially you 
could even have out-of-order boolean evaluation (ie echo "hello" && 
false does nothing) in a very well optimized language.

Using && in this way is technically a bit of a hack - the && operator 
was intended to evaluate a boolean expression and not as a replacement 
for "if".  That doesn't stop 99.9999999% of shell scripters from using 
it, however.  It is less of a hack than writing the equivalent of 30 
lines of code inside a for(<gobs of code> ; <gobs of code> ; <gobs of 
code>); statement in C.  :)


Replies:
Re: How to use &&
-- Duncan
Re: How to use &&
-- Barry Schwartz
References:
How to use &&
-- Paul Stear
Re: How to use &&
-- Martin Herrman
Re: How to use &&
-- Paul Stear
Re: How to use &&
-- Maciej Kazulak
Navigation:
Lists: gentoo-amd64: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: How to use &&
Next by thread:
Re: How to use &&
Previous by date:
Re: How to use &&
Next by date:
Re: How to use &&


Updated Jun 17, 2009

Summary: Archive of the gentoo-amd64 mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.