0

if I run

nrolland@mactoasty ~ $ type -p skhd   
skhd is /usr/local/bin/skhd

I can't compose it nicely with other command like

nrolland@mactoasty ~ $ la `type -p skhd`      
ls: is: No such file or directory
ls: skhd: No such file or directory
lrwxr-xr-x  1 nrolland  admin    29B Jun  4 09:35 /usr/local/bin/skhd -> ../Cellar/skhd/0.2.2/bin/skhd

What is the cleanest way to get only the second part ? (I am using zsh if that's any help)

  • Are you using zsh? – steeldriver Jun 13 '18 at 11:42
  • yes, using zsh. adding that to the question – nicolas Jun 13 '18 at 12:02
3

Use command -v skhd instead:

ls -l "$( command -v skhd )"

The command utility is a POSIX standard utility, and by using its -v flag it will output the path to the given utility, if it is found in $PATH, unless it's a function, alias or shell built-in utility.

  • technically that's the answer. though the zsh is the best fit for my particular environment. I will note this as the answer if people search for the same in the future. – nicolas Jun 13 '18 at 12:21
3

In zsh, type -p is verbose by default. From man zshbuiltins:

   type [ -wfpamsS ] name ...
          Equivalent to whence -v.

If you don't want the verbosity, you can use whence -p instead:

% type -p g++    
g++ is /usr/bin/g++
% whence -p g++  
/usr/bin/g++
  • I note the command answer as such if other people search for the same question in the future, as it's more portable, but thank you again – nicolas Jun 13 '18 at 12:22

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.