Bash 测试中的复合条件组

我希望在 Bash如果语句中包含一些条件组。具体来说,我要找的东西如下:

if <myCondition1 and myCondition2> or <myCondition3 and myCondition4> then...

如何按照我所描述的方式将条件组合在一起,以便与 Bash 中的一个 如果语句一起使用?

95974 次浏览

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