4

I was wondering if there is a built-in command in Bash (or even something OSX-specific) that would display the fully resolved path of a script that is in the current PATH environment variable.

For example, my PATH currently looks like this:

>: echo $PATH | tr ":" "\n"
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/opt/X11/bin
/Users/Josh/Dropbox/Scripts/Bash
/Users/Josh/Dropbox/Tools/WinRAR/OSX

And there's a script in Dropbox called get-azurelogs.sh. That path is in my PATH variable for convenience, but if I wanted to display the complete path to that script, assuming I wasn't sure where it was, is there an simple one-liner way to display the fully resolved path instead of testing it at each of the directories above?

6

You can use which. From the man page:

The which utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked

  • Boom. I knew there had to be something. Will accept the answer as soon as the mandatory waiting period is up. Thanks! – Josh Jun 24 '14 at 19:16
  • whoops, didn't see your answer initially. cheers! – njboot Jun 24 '14 at 19:18
4

A good alternative to which is the builtin type. The advantage being that type is also able to handle bash aliases and functions.

  • There's also type -P which restricts itself to executables on disk only - no aliases are shown. – Rich Homolka Jun 24 '14 at 22:40
2
which -a [nameofexecutable]

IE:

Macbook-Pro:~ njboot$ which -a chmod 
/bin/chmod
Macbook-Pro:~ njboot$ which -a nusers
/Users/njboot/bin/nusers

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .