Fork me on GitHub

Project Notes

#203 Tips and Tricks

I often use Homebrew to manage software installations on my Mac.

This is a collection of tips and tricks… basically things I use occasionally but always forget in the meantime.

Checking if a Package is Installed

Trick: use brew ls --versions to attempt to report on installed packages

I have mongodb installed:

$ brew ls --versions mongodb | grep -q mongodb
$ echo $?
0

But I don’t have talloc installed:

$ brew ls --versions talloc | grep -q talloc
$ echo $?
1

Combining a check for brew along with a check for a package

if [ $(which brew) ]
then
  brew_talloc_version=$(brew ls --versions talloc)
else
  brew_talloc_version="brew not installed"
fi
if echo "${brew_talloc_version}" | grep -q "talloc"
then
  echo "brew has talloc installed: ${brew_talloc_version}"
else
  brew install talloc
fi

Credits and References

About LCK#203 ToolsMacOS
Project Source on GitHub Return to the Project Catalog

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

LittleArduinoProjects LittleModelArt More on my blog