Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

&&||



function test ()
{
    _aaray=`ls`
    [ true ] && { print -l "${ _aaray[@]}" | GREP_COLOR='01;33' egrep --color=always "$1"\

| GREP_COLOR='01;31' egrep --color=always "$2" }\

|| echo bust!
}

   $ touch present

   $ test present pres
   present                            << two colors.

   $ test present pppres
   bust!

   $ test pppresent p
   bust!


When I first did this, I was puzzled by the output, then I wisely realized that the  '||'  was in fact responding to the return value of the failed egrep.  At first I did this without the braces and was content with what happened but I'd expect the braces to force the '||' to respond to the leading test (which of course never varies here being true all the time) and thus never give me a 'bust!' regardless of the egrep return value.  I solved the issue by using an 'if/else' construction but still I'm curious about the above.  Is my expectation mistaken?  Within an '&& ||' construction how would I write that to do as I was expecting -- respond to the truth value of the initial test?  When I use braces in complex '&& ||' situations they always seem to behave as expected.  I do have the niggling feeling my expectation above is wrong, but I can't quite say why.



Messages sorted by: Reverse Date, Date, Thread, Author