Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a program exists from a Fish script

Tags:

How can I check if a program exists within a fish script?

I know that there is no absolute solution with Bash, but using if type PROGRAM >/dev/null 2>&1; then... gave good results.

Is there something similar with fish?

like image 642
azmeuk Avatar asked Mar 16 '17 10:03

azmeuk


1 Answers

There is type -q, as in

if type -q $program      # do stuff end 

which returns 0 if something is a function, builtin or external program (i.e. if it is something fish will execute).

There is also command -sq, which will return 0 only if it is an external program.

For both of these the "-q" flag silences all output. For command the "-s" makes it just look for a command instead of executing it directly.

like image 133
faho Avatar answered Oct 04 '22 14:10

faho