How can I check if a program exists from a Bash script?

后端 未结 30 1949
有刺的猬
有刺的猬 2020-11-21 07:21

How would I validate that a program exists, in a way that will either return an error and exit, or continue with the script?

It seems like it should be easy, but it\

30条回答
  •  情书的邮戳
    2020-11-21 07:52

    Try using:

    test -x filename
    

    or

    [ -x filename ]
    

    From the Bash manpage under Conditional Expressions:

     -x file
              True if file exists and is executable.
    

提交回复
热议问题