bash输入:
if [[ 167 > 10800 ]]
then
echo "I can't compare"
fi
Run Code Online (Sandbox Code Playgroud)
bash 输出:
I can't compare
Run Code Online (Sandbox Code Playgroud)
我想这个问题很明显......
该>
字符不适用于您想要的比较类型。你必须使用-gt
:
if [[ 167 -gt 10800 ]]
then
echo "I can't compare"
fi
Run Code Online (Sandbox Code Playgroud)
如果你想做一个小于比较,你需要做-lt
. 要查看您需要执行哪些其他选项来进行比较,请查看test
联机帮助页。
从bash(1)
手册页引用:
当与 [[ 一起使用时,< 和 > 运算符使用当前语言环境按字典顺序排序。
所以 167 确实大于 10800,因为 6 是一个大于 0 的 ASCII 字符。
使用弧形括号进行真正的数字比较
if (( 167 > 10800 ))
then
echo "I can't compare"
fi
Run Code Online (Sandbox Code Playgroud)
很好的总结在这里:http : //fvue.nl/wiki/Bash : _Numeric_comparison
归档时间: |
|
查看次数: |
140 次 |
最近记录: |