4

I'm trying to test in a fish shell script for the existence of the figlet binary. Since I use Linux and OS X I cannot rely on the file being in the same location and need to resolve it dynamically. I'm used to doing this with $(which) in bash, which works.

With fish though this does not work properly. Why?

function print_hostname --description 'print hostname'
  if test -x (which figlet)
    hostname | figlet
  end
end

1 Answer 1

11

Use type in fish like in Bourne-like shell:

if type -q figlet
  hostname | figlet
end

Or to limit to executables in $PATH (ignoring functions, builtins):

if command -s figlet > /dev/null
  hostname | figlet
end

See also Why not use “which”? What to use then?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.