【发布时间】:2019-02-15 11:32:46
【问题描述】:
我正在尝试在 bash shell 中执行此操作。基本上想按百分比比较两个文件的大小。如果 file1 有 90% 不同,那么 file2 会做一些事情:
这是我目前所拥有的:
newsize=$(wc -c <"$newfile")
oldsize=$(wc -c <"$oldfile")
if [[ $(($oldsize * 0.9)) -ge $newsize ]]; then
echo 'This file is 90% or greater'
else
echo 'This file is not large enough'
fi
我在令牌“0.9”上得到一个无效的算术运算符错误 任何帮助或指针都会被占用
【问题讨论】:
-
bash不能自己做浮点数学,只能做整数数学。要么按照 Will 的建议转换为整数数学,要么部署bc、awk或其他一些工具来提供帮助。
标签: bash arithmetic-expressions