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

12

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?

1
  • The -s long form is --search. Commented Aug 23 at 0:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.