您好,欢迎访问一九零五行业门户网

如何在shell脚本中使用逻辑或&和

在我们的程序(脚本)中使用多个条件时,逻辑或&与操作非常有用。或在两个或多个条件之间使用。如果任何一个条件返回为true,则返回真。与在两个或多个条件之间使用。只有当所有条件都返回为真时,才会返回true。
使用逻辑或
逻辑或在bash脚本中与运算符-o一起使用。下面的shell脚本将展示如何在两个条件之间使用逻辑或(-o)。
#!/bin/bashread -p "enter first numeric value: " firstread -p "enter second numeric value: " secondif [ $first -le 10-o$second -gt 20 ]then echo "ok"else echo "not ok"fi
使用逻辑与
bash脚本中的逻辑与和运算符-a一起使用。下面的shell脚本将展示如何在两个条件之间使用逻辑与(-a)。
#!/bin/bashread -p "enter first numeric value: " firstread -p "enter second numeric value: " secondif [ $first -le 10-a$second -gt 20 ]then echo "ok"else echo "not ok"fi
逻辑或&与混合使用
下面的示例将介绍如何在单个语句中使用多个逻辑运算符。
#!/bin/bashread -p "enter your number:" iif [ ( $i -ge 10 -a $i -le 20 ) -o ( $i -ge 100 -a $i -le 200 ) ]then echo "ok"else echo "not ok"fi
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注的linux教程视频栏目!
以上就是如何在shell脚本中使用逻辑或&和的详细内容。
其它类似信息

推荐信息