Skip to content

Conversation

francoisPE
Copy link

@francoisPE
Copy link
Author

I propose that PR

@uroni
Copy link
Owner

uroni commented Jan 6, 2025

Usually && has precedence over ||. Is that not the case in bash?

@PhillipOConnor
Copy link

PhillipOConnor commented Feb 11, 2025

I believe && does not have precedence over || in the context as it is a list, not an expression. From "man bash":

A list is a sequence of one or more pipelines separated by one of the operators ;, &, &&, or ||, and optionally terminated by one of ;, &, or newline.
Of these list operators, && and || have equal precedence, followed by ; and &, which have equal precedence.
AND and OR lists are sequences of one or more pipelines separated by the && and || control operators, respectively. AND and OR lists are executed with left associativity.

In the context of an expression && does have precedence over ||

@uroni
Copy link
Owner

uroni commented Feb 15, 2025

~$ true && echo "A" || echo "B"
A
~$ false && echo "A" || echo "B"
B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants