Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: unintuitive bracketing with return value
On 2022-10-18 07:57, Eric Cook wrote:
https://mywiki.wooledge.org/BashPitfalls#pf22
Very well written! What breaks my intuition tho is the brackets.
Otherwise I quite understand that the last exit value is the active
one. I'm expecting the brackets to 'contain' the rv of any commands
within the brackets. But no, the left > right rule applies and the
brackets don't make any difference.
Roman:
1. Is the result coerced to bool (0 or 1)? Yes in C (and other
statically-typed languages), no in Zsh (and other dynamically-typed
languages).
2. Does && have higher precedence than ||? Yes in C (and most
languages), no in Zsh (and all shells).
... Even after all these years I still think in C. And, as Peter
explains, the braces don't really change anything at all, the last rv is
still the last rv. Indeed, it's best to stick with if/else and avoid
these little things. I really shouldn't have to have these basics
explained over and over :(
Messages sorted by:
Reverse Date,
Date,
Thread,
Author