我正在尝试运行一个脚本,其中每次在 while 循环中通过“作为用户输入给出”的 float 来更新变量。我知道 bash 不支持 float ,我尝试使用 | bc 但它似乎对我不起作用......
step_l0=0.25
step_l=0
while [ $step_l -le 2 ] do
step_r=$radius_input
while [ $step_r -le $radius_define ] do
stuff done in the while loops
step_r=$(( $step_r + $step_r0 ))
done
step_l=$(( $step_l + $step_l0 ))
done
最佳答案
每chepner的建议-
$: a=0.25
$: b=1.753
$: awk "BEGIN{ print $a + $b }"
2.003
$: python -c "print $a + $b"
2.003
$: perl -e "print $a + $b"$'\n'
2.003
在可能的情况下(实际上总是可能的),如果您需要调用更精确或更强大的语言来完成脚本中的任务,请考虑转换整个脚本。你会很高兴你这么做了。
关于bash - 如何在bash中对浮点变量求和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59140756/