d3p*_*3pd 70 bash if-statement
我希望在Bash if语句中包含一些条件组.具体来说,我正在寻找以下内容:
if <myCondition1 and myCondition2> or <myCondition3 and myCondition4> then...
Run Code Online (Sandbox Code Playgroud)
我如何按照我在Bash中使用if语句描述的方式将条件组合在一起?我感谢你对此有任何想法.
Wil*_*iam 147
使用&&(和)和|| (或)运营商:
if [[ expression ]] && [[ expression ]] || [[ expression ]] ; then
Run Code Online (Sandbox Code Playgroud)
它们也可以在单个[[]]中使用:
if [[ expression && expression || expression ]] ; then
Run Code Online (Sandbox Code Playgroud)
最后,您可以将它们分组以确保评估顺序:
if [[ expression && ( expression || expression ) ]] ; then
Run Code Online (Sandbox Code Playgroud)