Occasionally I run into a situation where I have more than one executable with
the same name installed in my $PATH
. This is to be expected, and it’s
generally not a problem until the executables are not found in the correct
order. And what is the correct order? Usually “correct” is whatever arbitrary
order makes sense for the thing that I’m currently doing, but it generally
means that I want the thing with the highest version number to be found first.
For instance, the bash
that ships with macOS is pretty old, so I generally
install whatever homebrew
has available and I want to default to that in
every case.
$ which -a bash
/opt/homebrew/bin/bash
/bin/bash
Now, if I want to know which version of each is currently installed, I just
have to remember the correct incantation for bash
. Is it?
bash version
bash -v
bash -V
exec bash --version
bash --version
It’s the last one (and also the next to last, which has some cleaner output). Probably the last would have been my first guess, but maybe not, depending on how much of a hurry I am in.
If I’m curious about which versions are actually installed, I just need to copy
each path and run --version
on it. That’s ok, but it’s a bit clumsy. I could
also cobble together some command line magic, but now I’ve really become
distracted from the task at hand. Since I have
is: an inspector for your environment
installed, this becomes a bit easier.
$ is there bash --all
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Path ┃ Version ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━┫
┃ /opt/homebrew/bin/bash ┃ 5.2.37 ┃
┃ /bin/bash ┃ 3.2.57 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━┛
What if I’d rather see it as JSON
?
is there bash --all --json
[
{
"path": "/opt/homebrew/bin/bash",
"version": "5.2.37"
},
{
"path": "/bin/bash",
"version": "3.2.57"
}
]
Now I can use jq
to get the version of the macOS installed executable.
$ is there bash --all --json | jq '.[1].version'
"3.2.57"
I don’t know offhand why I would want to do that, but the important thing is that I can.
"Numbers" by andymag is licensed under CC BY 2.0
It gets interesting with things I may have even more versions of. Maybe the latest version is not where I think it is:
$ is there perl --all
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Path ┃ Version ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━┫
┃ /Users/olaf/.plenv/shims/perl ┃ v5.40.0 ┃
┃ /opt/homebrew/bin/perl ┃ v5.40.2 ┃
┃ /usr/bin/perl ┃ v5.34.1 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━┛
Possibly this can help me find things that I no longer need. It looks like
Mason has been managing my gopls
install for a while. I can probably delete the first gopls
in my $PATH
.
$ is there gopls --all
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Path ┃ Version ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━┫
┃ /Users/olaf/go/bin/gopls ┃ 0.15.3 ┃
┃ /Users/olaf/.local/share/nvim/mason/bin/gopls ┃ 0.18.1 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━┛
Because I work with computers, my days are full of minutia that slow me down. Little quality of life improvements can go a long way towards removing these tiny roadblocks. is: an inspector for your environment may be helpful to you as well.