【发布时间】:2019-04-07 04:55:34
【问题描述】:
这是我的一段代码
if [ $totalavg -gt 1000000 ]; then
printf "%0.1f MB/s (average)\n" $(echo "scale=1; $totalavg/100000" | bc)
elif [ $totalavg -gt 1000 ]; then
printf "%0.1f KB/s (average)\n" $(echo "scale=1; $totalavg/1000" | bc)
else
printf "%i B/s (average)\n" "$totalavg"
fi
totalavg 变量是从 /proc/ 文件中获取的整数。直到整数大于 1000 才能到达 if 语句之一,结果证明
./script.sh: row (with second if above 1000): printf: 1.7: wrong number
我已经浪费了 2 个小时的时间来解决这个超级基本的可笑问题。但我无法修复它,我不知道发生了什么。
【问题讨论】:
标签: bash variables numbers integer