我试图在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”上得到一个无效的算术运算符错误任何帮助或指针都会被占用
尝试使用整数数学(例如9/10
)而不是浮点数。
newsize=525
oldsize=584
if [[ $(($oldsize * 9/10)) -ge $newsize ]]; then
echo 'This file is 90% or greater'
else
echo 'This file is not large enough'
fi
This file is 90% or greater