10

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?

Evan Carroll
  • 30,763
  • 48
  • 183
  • 315

1 Answers1

13

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:

igal
  • 9,886