bash - 数字平均值(Bc 命令未找到错误)
问题描述
我想找出给定数字的平均值,但下面的代码显示了我:
main.bash:第 8 行:bc:找不到命令
请大家帮我看看我错在哪里?
代码片段:
read count
sum=0
for((i=0;i<count;i++))
do
read var
sum=`expr $sum + $var`
done
res=`echo "$sum / $count" | bc -l`
printf "%.3f" $res
解决方案
运行type -a bc
,如果它返回:
-bash: type: bc: not found
然后,您必须在系统中安装bc
软件包。
推荐阅读
- string - strings.Builder 内存使用情况
- javascript - 默认情况下,Firestore 可以为离线(和未经身份验证的)用户在 IndexedDB 中存储数据吗?
- amazon-web-services - Terraform - Count.index 和 String 在一起
- r - RSelenium 无法在带有下拉列表的页面上找到元素
- java - Spring Data JDBC - 多对一关系
- javascript - React onChange 处理状态对象
- macos - 为什么除非我删除以前的可执行文件,否则使用 x86_64 构建系统构建的本机 arm64 应用程序无法进行代码签名?
- xml - 如何将纯空白元素读入 QDomDocument?
- node.js - 如何使用 Axios 测试 HTTP Only Cookie Set
- python-3.x - Python ThreadPoolExecutor 不运行最大