检测是否安装了自制程序包

编程入门 行业动态 更新时间:2024-10-25 08:25:38
本文介绍了检测是否安装了自制程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将要编写一个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.

更多推荐

检测是否安装了自制程序包

本文发布于:2023-11-16 09:33:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序包   安装了

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!