我的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
如何使用OR并拥有单个if子句?
答案 0 :(得分:38)
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
答案 1 :(得分:38)
您应该可以使用||
或-o
我认为如下:
if [ $uptime -lt 0 ] || [ $questions -lt 1 ] || [ $slow -gt 10 ]; then
some code
fi