将变量与Shell中的整数进行比较? [英] Compare variable with integer in shell?
本文介绍了将变量与Shell中的整数进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只要存储在我的$counter
变量中的值大于5
,我就有一个if语句需要运行.
I have an if statement I need to run, as long as the value I have stored in my $counter
variable is greater than 5
.
这是我当前(无法运行的)脚本的相应部分:
Here is the respective section of my current (non-functioning) script:
if $counter > 5
then
echo "something"
fi
我犯的错误可能非常明显,但是由于某种原因,我无法在线找到解决方案. 谢谢!
The mistake I'm making is probably very obvious, but for some reason I couldn't find the solution online.. Thanks!
推荐答案
这很简单:
if [ "$counter" -gt 5 ]
then
echo "something"
fi
这篇关于将变量与Shell中的整数进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文