On Thu, Oct 10, 2002 at 12:25:25PM +0930, Mark Bradbury wrote:
> Any bash shell masters out there?
> 
> Can someone explain why the statement 
> false && true && echo 1 || true && false && echo 2 || false || true || echo 3 && 
>echo 4 && echo 5
> 
> prints out
> 4
> 5
> 
> and not
> 3
> 4
> 5
> 

Its an old trick,  Any && expression stops evaluation at the first false 
value it gets, any || expression stops at the first true value it gets.
(&& = AND, || = OR )

So the only part you have to look at is:

  true || echo 3 && echo 4 && echo 5

Which is better understood as : ( true || echo 3) && (echo 4 && echo 5)
or  (X) && (Y)

As soon as "true" is encountered in  (X) it stops evaluating that part
of the statement, (so the "echo 3" is never evaluated), and goes to the
&& separating the two paren groups.  Since its an && statement the (Y)
has to be evaluated to determine if the entire statement is true.

Since the (Y) expression is also an "AND" statement both subexpressions
"echo 4" and "echo 5" have to be evaluated.

Next question - How does bash determine precedence in an expression ?
(critical to the above... )


-- 
Jeff Kinz, Director, Emergent Research,  Hudson, MA.  "[EMAIL PROTECTED]" 
"[EMAIL PROTECTED]" copyright 2002.  Use is restricted. Any use is an 
acceptance of the offer at http://users.rcn.com/jkinz/policy.html.

    (o-                                    -o)
    //\         eLviintuaxbilse            /\\
    V_/_                                  _\_V   



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to