Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

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

share|improve this answer
    
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 at 19:16
    
whoops, didn't see your answer initially. cheers! –  njboot Jun 24 at 19:18
add comment
which -a [nameofexecutable]

IE:

Macbook-Pro:~ njboot$ which -a chmod 
/bin/chmod
Macbook-Pro:~ njboot$ which -a nusers
/Users/njboot/bin/nusers
share|improve this answer
add comment

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

share|improve this answer
    
There's also type -P which restricts itself to executables on disk only - no aliases are shown. –  Rich Homolka Jun 24 at 22:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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