How can I check if c-blosc is installed using the command line?

Viewed 182

Using command -v c-blosc returns nothing, even though it's installed

c-blosc describes themselves as a compression library, so it's not a command


A few things I've tried

% c-blosc
zsh: command not found: c-blosc
where c-blosc
c-blosc not found
brew install c-blosc
...
Warning: c-blosc 1.21.0 is already installed and up-to-date.
To reinstall 1.21.0, run:
  brew reinstall c-blosc

% brew info c-blosc
c-blosc: stable 1.21.0 (bottled)
Blocking, shuffling and loss-less compression library
https://blosc.org/
/usr/local/Cellar/c-blosc/1.21.0 (10 files, 1.7MB) *
  Poured from bottle on 2021-07-07 at 23:44:40
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/c-blosc.rb
License: BSD-3-Clause
==> Dependencies
Build: cmake ✘
==> Analytics
install: 312 (30 days), 1,190 (90 days), 3,168 (365 days)
install-on-request: 249 (30 days), 998 (90 days), 2,263 (365 days)
build-error: 0 (30 days)
brew search c-blosc 
==> Formulae
c-blosc ✔

The following

if [ brew info c-blosc 2>&1 >/dev/null ]; then
    echo "Installed"
else
    echo "Nope"
fi

and

if [ brew search c-blosc 2>&1 >/dev/null ]; then
    echo "Installed"
else
    echo "Nope"
fi

both print Nope even though I have it installed

2 Answers

According to https://apple.stackexchange.com/q/145437, you can just do

brew info c-blosc

That will print, among other things, the install location. You can use related commands, like search:

brew search c-blosc

The only command explicitly documented to return a fail code for missing formulas is

brew --prefix --installed c-blosc

It has no output specifically so that you can do

if brew --prefix --installed c-blosc 2>/dev/null; then
    echo "Installed"
else
    echo "Nope"
fi

As the c-blosc package doesn't include any commands, you won't find if it is installed using either of these:

command c-blosc
type c-blosc

The package actually provides a dynamic link library and a header file, which you can see by using the following command to list the package contents:

brew ls c-blosc

/usr/local/Cellar/c-blosc/1.21.0/include/ (2 files)
/usr/local/Cellar/c-blosc/1.21.0/lib/libblosc.1.21.0.dylib
/usr/local/Cellar/c-blosc/1.21.0/lib/pkgconfig/blosc.pc
/usr/local/Cellar/c-blosc/1.21.0/lib/ (3 other files)

Now homebrew creates symbolic links in /usr/local/lib for you to link your programs against - let's look:

ls -l /usr/local/lib/*blosc*
lrwxr-xr-x  1 mark  admin  50 14 Jul 07:52 /usr/local/lib/libblosc.1.21.0.dylib -> ../Cellar/c-blosc/1.21.0/lib/libblosc.1.21.0.dylib
lrwxr-xr-x  1 mark  admin  45 14 Jul 07:52 /usr/local/lib/libblosc.1.dylib -> ../Cellar/c-blosc/1.21.0/lib/libblosc.1.dylib
lrwxr-xr-x  1 mark  admin  39 14 Jul 07:52 /usr/local/lib/libblosc.a -> ../Cellar/c-blosc/1.21.0/lib/libblosc.a
lrwxr-xr-x  1 mark  admin  43 14 Jul 07:52 /usr/local/lib/libblosc.dylib -> ../Cellar/c-blosc/1.21.0/lib/libblosc.dylib

So, the most generic of these, which will exist regardless of version, is libblosc.dylib, so I would use this as my test:

if [ -e /usr/local/lib/libblosc.dylib ] ; then echo "Installed" ; fi

Note that you could test more explicitly for that file existing and being a symlink with if [ -L ... ] but that may not work if liblosc is installed by some non-symbolic-linking method, e.g. from source which may copy an actually library to that location rather than making a symlink.


Another, alternative command that would work is the following which shows you where a given homebrew package is installed:

brew --prefix --installed c-blosc
/usr/local/opt/c-blosc
echo $?
0

As opposed to:

brew --prefix --installed MadeUpNonExistentPackage
Error: No available formula with the name "madeupnonexistentpackage".
echo $?
1
Related