Check if a program exists from a Fish script

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 -q, which will return 0 only if it exists as an external program
  • builtin -q, which will return 0 only if it is a fish builtin
  • functions -q, which will return 0 only if it is a fish function

For all of these the “-q” flag silences all output and just queries for existence.

If e.g. builtin -q returns true, that just means it is also a builtin – it can still be a function or command as well.

command -q works since fish 3.1.0 because the -q flag implies -s, before it would have to be command -sq.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)