【发布时间】:2021-09-01 05:39:06
【问题描述】:
我创建了 5 个仅包含浮点数(包含正数和负数)的数组。
以下是声明的数组:
- 资产
- 报告
- 借记
- 学分
- 附属
- 贷款
我需要对数组执行以下公式,但它不起作用。
还有其他方法吗?
for((i =1 ; i <(#$assets[@]}; i++));do
echo ${assets[i]} - ( ${reported[i]} + ( ${affiliate[i]} * -1 ) + ${loans[i]} + (${credit[i]} - ${debit[i]})) | bc >> test.log
【问题讨论】:
-
echo "..." | bc >> test.log -
@blackhole : 还有其他方法吗。请协助:Stack Overflow 不鼓励有关建议和意见的问题,所以我将我的意见作为评论告诉你,而不是答案:我会考虑使用可以进行浮点运算的 shell(例如 zsh) ,或使用内置支持浮点的编程语言(Ruby、Perl、....)。
-
另外,您还有语法错误。通过 shellcheck.net 运行它。我想你的意思是
i < ${#assets[@]}
标签: arrays bash shell arithmetic-expressions