小编Ahm*_*buğ的帖子

如何在Bash中对文件中的变量求和

我需要逐行对文件中的数字求和。

文件:

1.0
0.46
0.67
Run Code Online (Sandbox Code Playgroud)

我想求和,然后除以 3。

我目前有:

while IFS= read -r var
do
   x=$(($var + $x)) | bc -l
done < "file.txt"
echo "$x / 3"
Run Code Online (Sandbox Code Playgroud)

我的错误:

-bash: 1.0 + 0: syntax error: invalid arithmetic operator (error token is ".0 + 0")
Run Code Online (Sandbox Code Playgroud)

bash arithmetic

3
推荐指数
1
解决办法
2408
查看次数

标签 统计

arithmetic ×1

bash ×1