Groups of compound conditions in Bash test

BashIf Statement

Bash Problem Overview


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?

Bash Solutions


Solution 1 - 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiond3pdView Question on Stackoverflow
Solution 1 - BashWilliamView Answer on Stackoverflow