Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: &&||
On Tue, Feb 20, 2018 at 11:24 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> On 20/02/18 09:07 AM, Peter Stephenson wrote:
>>
>> You've now extended your demand so that it works with an else clause as
>
> Not 'extended' that is the entire point of my question. I'm expecting the
> '||' to be identical to a logical 'else', there is no other issue.
But "||" is not "else" and "&&" is not "if" -- rather they are "and" /
"or" (which is why they use the symbols they do).
first-statement AND second-statement OR third-statement
The implicit grouping is left-to-right, so that's the same as
{ first-statement AND second-statement } OR third-statement
Thus the first pair succeeds only when both succeed, and
third-statement occurs when the first pair fails. To express this
with if/else you would write
if first-statement;
then
if second-statement;
then
true;
else
false;
fi;
else
false;
fi;
if [[ $? -eq 0 ]];
then
if third-statement;
then
true;
else
false;
fi;
else
false;
fi
> Demand? I seek clarification
I believe PWS meant "demand" in the sense of what your statement asks
of the shell, not what you're asking him to explain.
> Braces are
> ignored as far as truth tests on the left of any && or ||.
No, that's entirely wrong. Braces always return the final status of
the enclosed list of statements. && and || always use the final
status of the entire chain of any && or || to their left. The two are
related only when the braces surround another chain of && or || but
only in so far as that affects the final status of the braces.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author