如何做到在Shell脚本逻辑或操作 [英] How to do a logical OR operation in Shell Scripting
本文介绍了如何做到在Shell脚本逻辑或操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个简单的条件检查,但似乎并没有工作。
如果 $#
等于 0
或大于 1 $更大C $ C>然后打个招呼。
我曾尝试下面的语法,但没有成功:
如果[$#== 0 -o$#> 1];然后
回声你好
科幻如果[$#== 0] || [$#> 1];然后
回声你好
科幻
解决方案
这应该工作正常。
如果[$#== 0] || [$#-gt 1];然后
回声你好
科幻
我不知道这是在其他炮弹不同,但如果你想使用<,>,你需要把它们放在双括号里面,像这样:
IF(($#> 1))
...
I am trying to do a simple condition check, but it doesn't seem to work.
If $#
is equal to 0
or is greater than 1
then say hello.
I have tried the following syntax with no success:
if [ "$#" == 0 -o "$#" > 1 ] ; then
echo "hello"
fi
if [ "$#" == 0 ] || [ "$#" > 1 ] ; then
echo "hello"
fi
解决方案
This should work OK.
if [ "$#" == 0 ] || [ "$#" -gt 1 ] ; then
echo "hello"
fi
I'm not sure if this is different in other shells but if you wish to use <, >, you need to put them inside double parenthesis like so:
if (("$#" > 1))
...
这篇关于如何做到在Shell脚本逻辑或操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文