9

I'm now using

silent! let l:status = system(l:command . ' > /dev/null') if match(l:status, '\cunknown') != -1 || match(l:status, '\cnot') != -1 echo 'command not found' return 0`enter code here` endif 

i know it's not complete but is there any better way to check?

edit

i'm now using

silent! let l:status = system('which espeak') if l:status !~ '\w\+' echo 'command not found' return 0 endif 

edit

changed from which to command https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then

5
  • 1
    In bash, my standard is command -v <command name> >/dev/null and check the exit code. Commented Jul 20, 2018 at 2:49
  • @D.BenKnoble is which better? i'm using fish and i just fund command -v in bash is command -s in fish, but which is all the same Commented Jul 20, 2018 at 3:18
  • which only works on external utilities, so not shell builtins. Commented Jul 20, 2018 at 3:34
  • 1
    @wengwengweng unix.stackexchange.com/questions/85249/… Commented Jul 20, 2018 at 8:17
  • @wengwengweng if the solution you found is satisfying you can answer your own question (instead of editing it), that will make it more useful and easier to read for future users with the same question. Commented Jul 20, 2018 at 11:21

2 Answers 2

21

Incidentally vim has a special function just for this: executable().

2

thanks for the comments above, i'm using this code right now:

silent! let l:status = system('command -v ' . l:cmd) if l:status !~ '\w\+' echo 'command not found' return -1 endif 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.