vpvvna
Last Updated: February 25, 2016
·
1.752K
· sheerun
Photo on 08.01.2013 at 04.15

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
Say Thanks
Respond

3 Responses
Add your response

5418
0563a94bb4428b9410f1e36e894f397a

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
Photo on 08.01.2013 at 04.15

Hmm. OSX. I've changed the code.

over 1 year ago ·
16102
11d948cbd083298dea9f4f32c71f6427

You could also use which like:

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