vpvvna
Last Updated: February 25, 2016
·
2.377K
· 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

5418

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

over 1 year ago ·
5420

Hmm. OSX. I've changed the code.

over 1 year ago ·
16102

You could also use which like:

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