Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to detect if an external command exists (i.e. wget, svn)?

More specifically today, i was trying to run one of my scripts i wrote and the person didn't have wget or svn installed.

The script just downloads a file extracts it or uses svn to export the trunk.

share|improve this question
wget and svn are not functions, they're external commands (also called utilities, which includes built-in utilities). Functions are defined by shell code and live inside the current shell instance. External commands are stored in executable files and can be implemented in any language. – Gilles Sep 1 '11 at 23:53
Thank you. I wasn't sure about the terminology there; still have a lot to learn. – chrisjlee Sep 2 '11 at 1:29
If you are using Ubuntu or Debian you may be interested in the command-not-found package. – Faheem Mitha Sep 4 '11 at 1:10
up vote 13 down vote accepted

In Bash the type shell built-in gives information about the executable things: aliases, functions, executables. See help type for details.

# just check for existence
type -t 'yourfunction' > /dev/null || echo 'error: yourfunction not found'

# explicitly check for given type
[[ "$( type -t 'yourfunction' )" != 'function' ]] && \
    echo 'error: yourfunction not found or is not a function'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.