24
我的shell脚本,看起来像这样...使用或shell脚本
if [[ $uptime -lt 0 ]];then
some code
fi
if [[ $questions -lt 1 ]];then
some code
fi
if [[ $slow -gt 10 ]];then
some code
fi
如何使用或并有一个单一的if语句?
我的shell脚本,看起来像这样...使用或shell脚本
if [[ $uptime -lt 0 ]];then
some code
fi
if [[ $questions -lt 1 ]];then
some code
fi
if [[ $slow -gt 10 ]];then
some code
fi
如何使用或并有一个单一的if语句?
if [ $uptime -lt 0 -o $questions -lt 1 -o $slow -gt 10 ] ; then
some code
fi
有关可用的语法和选项,请参见man test
。该[
操作是test
只是简写,所以上面的代码就相当于:
if test $uptime -lt 0 -o $questions -lt 1 -o $slow -gt 10 ; then
some code
fi
您应该能够使用||
或-o
我认为如下:
if [ $uptime -lt 0 ] || [ $questions -lt 1 ] || [ $slow -gt 10 ]; then
some code
fi
? sh,bash? – 2010-11-19 08:39:11
[如何在Shell脚本中执行逻辑或操作](https://stackoverflow.com/questions/4111475/how-to-do-a-logical-or-operation-in-shell-scripting) – 2017-06-28 11:16:00