Find the install location of brew on OS X

Viewed 17531

I'm creating a BASH scrip which requires a couple of applications to be installed. ffmpeg and sox

To ensure they are in place when my script runs I first check for the installation of Homebrew with :

#!/bin/bash
which -s brew
if [[ $? != 0 ]] ; then
    # Install Homebrew
    /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
fi

Then I check that sox and ffmpeg are installed with :

echo "---- checking for sox ----"
which -s sox || /usr/local/bin/brew install sox

echo "---- checking for ffmpeg ----"
which -s ffmpeg || /usr/local/bin/brew install ffmpeg

The problem I am facing is when Homebrew is installed but in a non-standard location.

I have to use the full path to Homebrew because this script is being run within Playtypus.

So the question is : How can I reliably get the installed path of Homebrew in a BASH script?

2 Answers

Just to add to this, Homebrew's --prefix mode has been enhanced here in the far-flung future of 2020 (or maybe it was always this way), so that it now takes a package name as an argument. Meaning locating those "keg-only" packages which aren't linked into standard paths is as easy as:

$ brew --prefix ffmpeg
/usr/local/opt/ffmpeg
Related