This question already has an answer here:

I'm just curious to know how to best check if a program exists. I've seen solutions with

  • test
  • command
  • hash
  • type
  • which
  • [

Which is the best method, is there a right answer? What does the POSIX and LSB specs say about this?

marked as duplicate by Evan Carroll, cuonglm shell-script Nov 13 '17 at 3:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You probably want to use the command command, e.g.:

command -v <the_command>

For more discussion see the following StackOverflow posts:

Also see the following Unix StackExchange post:

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