Last Updated: February 25, 2016
·
3.142K
· sheerun

Check if given executable exists (all shells)

exists() { type -t "$1" > /dev/null 2>&1; }

if exists brew; then
  echo 'Homebrew found!'
fi

if ! exists brew; then
  echo 'Homebrew not found!'
fi

3 Responses
Add your response

Which distro do you use? On my Arch Linux and my Centos 6 "which" program does not have "-s" option.

over 1 year ago ·

Hmm. OSX. I've changed the code.

over 1 year ago ·

You could also use which like:

exists() { [ ! -z `which "$1"` ]; }
over 1 year ago ·