1 |
Maciej Kazulak wrote: |
2 |
> That's how bash evaluates logic expressions. There's even a fancy word |
3 |
> for it i think. Point is it will execute commands only to the point |
4 |
> where it can determine the logic result. |
5 |
|
6 |
The fancy word for it would probably be short circuit evaluation: |
7 |
|
8 |
http://en.wikipedia.org/wiki/Short-circuit_evaluation |
9 |
|
10 |
When placing code in a boolean expression it is critical to understand |
11 |
whether the boolean operator will be evaluated in a short-circuit |
12 |
fashion in any language. |
13 |
|
14 |
I'm not aware of any language that works this way, but potentially you |
15 |
could even have out-of-order boolean evaluation (ie echo "hello" && |
16 |
false does nothing) in a very well optimized language. |
17 |
|
18 |
Using && in this way is technically a bit of a hack - the && operator |
19 |
was intended to evaluate a boolean expression and not as a replacement |
20 |
for "if". That doesn't stop 99.9999999% of shell scripters from using |
21 |
it, however. It is less of a hack than writing the equivalent of 30 |
22 |
lines of code inside a for(<gobs of code> ; <gobs of code> ; <gobs of |
23 |
code>); statement in C. :) |