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

Re: this && that || the other && this too



On Oct 7,  7:47pm, ramos@xxxxxxxxxxxxxxxxxxxx wrote:
} Subject: this && that || the other && this too
}
} Apparently there is no way to construct an expression
} using "&&" and "||" of the form:
} 
} 	cmd1 XX cmd2 XX cmd3
} 
} such that both cmd2 and cmd3 execute when cmd1 succeeds,
} and neither cmd2 nor cmd3 execute when cmd1 fails.

Yes, that's correct.  `&&' and `||' behave mostly like the boolean
operators in C, so they execute exactly as many subexpressions, left to
right, as are needed to determine the success or failure status of the
entire expression.  They differ from C in having equal precedence, so
they evaluate strictly left to right unless grouped with ( ) or { }.

This is distinct from `;' and `&' which execute both the left and right
subexpressions regardless of the exit status of the left one.

} "It would be nice" to be able to do this without using ()'s, or
} if/then/fi, or some other contorted workaround.

It would be confusing, is what it would be.

What you want, it sounds like, is

	cmd1 && { cmd2 ; cmd3 }

The only way to get that without the { } would be to introduce a new
command separator that acted like `;' but that had higher precedence
than `&&'.  That behavior would be unlike any other separator in zsh
or any other shell.

There's nothing "contorted" about the { } form.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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