Bash 测试中的复合条件组 [英] Groups of compound conditions in Bash test
本文介绍了Bash 测试中的复合条件组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Bash if 语句中包含一些条件组.具体来说,我正在寻找如下内容:
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...
如何按照我描述的方式将条件组合在一起,以便与 Bash 中的一个 if 语句一起使用?感谢您对此的任何想法.
How may I group the conditions together in the way I describe for use with one if statement in Bash? I thank you for any ideas you may have on this.
推荐答案
使用 &&(and) 和 ||(或)运营商:
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
这篇关于Bash 测试中的复合条件组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文