我想将浮点变量与整数进行比较.我知道这不是最好用bash做的,但我的整个脚本已经用bash编写了.$ number可以是任何整数.如果它低于或等于50,我想要output1,对于所有其他我想要输出与另一个变量k.这是我到目前为止:
number=43
test=$(echo "scale=2; $number/50" | bc -l)
echo "$test"
for k in {1..5}
do
if ["$test" -le 1]
then echo "output"
elif ["$test" -gt $k]
then echo "output$k"
fi
done
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用test = 0.43,则第一个循环甚至不起作用.我认为它与整数和浮点比较有关,但不能使它工作.
我错过了什么?
PS:这[0.43: command not found是终端输出的内容.