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
Written by Adam Stankiewicz
Related protips
3 Responses

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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Zsh
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#