Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
shell脚本给我带来了麻烦。它应该在每次迭代时显示一些增加的值。除以“1/9”是问题的根源,将计数设置为“1.0”应该可以解决问题,但会给我一个错误:'Illegal number: 1.0'
count=1 rtime=9 until [ $count -eq $rtime ] do echo $((($count/$rtime)*10)) sleep 1 count=$(($count+1)) done
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
shell 只能进行整数运算。对于花车,您可以尝试bc.
bc