Check if a program exists from Fish script

How to 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... if type PROGRAM >/dev/null 2>&1; then... gave good results.

Is there something similar with fish?

+5
source share
1 answer

There is type -q , as in

 if type -q $program # do stuff end 

which returns 0 if something is a function, an internal or external program (i.e. if it is something that will make fish).

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

For both of them, the -q flag disables all output. For the -s command, it forces it to simply look for the command, and not execute it directly.

+16
source

Source: https://habr.com/ru/post/1265545/


All Articles