shell脚本给我带来了麻烦。它应该在每次迭代时显示一些增加的值。划分“1/9”是问题的根源,将设置计数设置为“1.0”应该可以解决问题,但却给出了错误:'非法数字:1.0'
count=1
rtime=9
until [ $count -eq $rtime ]
do
echo $((($count/$rtime)*10))
sleep 1
count=$(($count+1))
done
答案 0 :(得分:1)
set -o nounset # Treat unset variables as an error
count=1
rtime=9
until [ $count -eq $rtime ]
do
echo $(echo "scale=2; $((count*10))/$rtime" | bc)
sleep 1
count=$((count+1))
done
答案 1 :(得分:0)
shell只能做整数算术。对于花车,您可以尝试bc
。