【问题标题】:"free command not found" while running bash script using git bash使用 git bash 运行 bash 脚本时出现“找不到免费命令”
【发布时间】:2016-08-12 17:35:32
【问题描述】:

我想在 bash 脚本中显示服务器负载、磁盘空间、使用情况和内存使用情况。

但是当我尝试时

echo "Memory usage:"
memory_usage=$ free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
echo $memory_usage

这并使用./test.sh 运行脚本它给了我错误:

找不到空闲命令

【问题讨论】:

  • 如果你说which free会得到什么?
  • 存储命令的输出,比如var=$(command)。您的 var=$ command 错误 - 请注意命令周围的空格和缺少括号。
  • 当我当时使用 git bash 运行脚本时,我运行免费,但也给了我找不到免费命令的错误
  • memory_usage=$(free -m | awk 'NR==2{printf "内存使用:%s/%sMB (%.2f%%)\n", $3,$2,$3* 100/$2 }') 这也是同样的错误。
  • 这显然意味着您没有安装free 包。检查How to add more commands to Git Bash Shell

标签: shell git-bash


【解决方案1】:

对于 debian /ubuntu 。跑吧

apt-get install procps 

为centos

yum install procps

procps 包括 free , top 等 linux base commond

【讨论】:

  • 如何为 macOS 安装 bash FREE
猜你喜欢
  • 2019-12-26
  • 1970-01-01
  • 1970-01-01
  • 2016-09-27
  • 2017-08-10
  • 2020-08-14
  • 2012-04-12
  • 2019-04-15
  • 2016-06-19
相关资源
最近更新 更多