在Bash中测试复合条件组 [英] groups of compound conditions in Bash test
本文介绍了在Bash中测试复合条件组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一些条件组如果语句猛砸。具体来说,我正在寻找类似如下:
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...
怎么可能I组的条件在一起的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.
推荐答案
使用了与放大器;&安培; (和)和|| (或)运算符:
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屋!
查看全文