检测是否安装了自制程序包 [英] Detect if homebrew package is installed

查看:63
本文介绍了检测是否安装了自制程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要编写一个Shell脚本来检测系统中是否安装了几个自制程序包.有没有一种方法可以使用brew命令来实现这一目标?

I'm about to write a shell script to detect if several homebrew packages are installed in the system. Is there a way to use a brew command to achieve that?

我尝试使用brew install <formula> --dry-run的退出代码.但这会构建缺少的软件包.

I tried using the exit code of brew install <formula> --dry-run. But this builds the package if it is missing.

推荐答案

您可以使用

brew ls --versions myformula

输出相应公式的已安装版本.如果未安装该公式,则输出将为空.

to output the installed versions of the respective formula. If the formula is not installed, the output will be empty.

使用brew update可获得的最新版本的自制软件时,只需运行以下命令即可(感谢Slaven):

When using a recent versions of homebrew, which you can get with brew update, you can just run this (thanks Slaven):

if brew ls --versions myformula > /dev/null; then
  # The package is installed
else
  # The package is not installed
fi

也就是说,最好检查一下该工具是否存在,而不仅仅是检查各自的自制软件包(例如,通过在$PATH中搜索可执行文件).人们倾向于在实践中以大量方式安装工具,而自制软件只是其中一种.

That said, it is probably a good idea to check for the existence of the tool at all and not just checking for the respective homebrew package (e.g. by searching for the executable in the $PATH). People tend to install tools in a rather large amount of ways in practice, with homebrew being just one of them.

这篇关于检测是否安装了自制程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆