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

后端 未结 30 1947
有刺的猬
有刺的猬 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

    I never did get the previous answers to work on the box I have access to. For one, type has been installed (doing what more does). So the builtin directive is needed. This command works for me:

    if [ `builtin type -p vim` ]; then echo "TRUE"; else echo "FALSE"; fi
    

提交回复
热议问题