Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I want to have some groups of conditions in a Bash
if
statement. Specifically, I'm looking for something like the following:
if <myCondition1 and myCondition2> or <myCondition3 and myCondition4> then...
How may I group the conditions together in the way I describe for use with one if statement in Bash?
–
–
–
Use the && (and) and || (or) operators:
if [[ expression ]] && [[ expression ]] || [[ expression ]] ; then
They can also be used within a single [[ ]]:
if [[ expression && expression || expression ]] ; then
And, finally, you can group them to ensure order of evaluation:
if [[ expression && ( expression || expression ) ]] ; then
–
–
–
–
–