What is the best method to test if a program exists for a shell script?
18,539
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:
Author by
Brandon Condrey
Consider opposing apartheid in Palestine and signing onto the BDS Movement; #1 User for DBA.SE 2017. Available for contracting: 281.901.0011 PostgreSQL & PostGIS / MySQL / SQL Server JavaScript, Typescript, Rx.js, Node.js, Angular Also: C / Perl / Python / Rust / x86 Assembly
Updated on September 18, 2022Comments
-
Brandon Condrey almost 2 years
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?
-
Brandon Condrey over 6 yearsThanks but this a dupe of this, unix.stackexchange.com/questions/85249/…
-
igal over 6 years@EvanCarroll Yeah, I just saw that. Well... problem solved!