Re: Conditions with logical operators and nested groups execute "if" and
From:
PePa
Subject:
Re: Conditions with logical operators and nested groups execute "if" and "else"
Date:
Thu, 31 May 2018 20:05:12 +0700
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0
On 05/31/2018 01:54 PM, Robert Elz wrote:
> I am not sure what predence rule you see working as
> expected, but in sh (bash, or any other Bourne syntax
> or POSIX shell) there is no precedence for && and ||
> they (in the absense of grouping) are simply executed
> left to right as written.
Here is an easy way to figure out how and/or-lists work: Given that &&
and || have the lowest precedence of all operators (except for ; and &),
they can be thought of as concatenating commands/blocks/pipelines, and
the execution rule for an and/or-list is:
If the exit-status of the command/block/pipeline is 0, continue after
the next &&, otherwise continue after the next || in the and/or-list.
Cheers,
Peter