8

which -a ruby gives me

/usr/ruby
/usr/ruby
/usr/ruby

It gives the same path three times. Why does this happen?

9

Check your path. It's not that hard to end up with duplicates in it. Example:

»echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:
»which -a bash
/bin/bash
/usr/bin/bash

This is because my /bin is a symlink to /usr/bin. Now:

»export PATH=$PATH:/usr/bin
»echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/bin
»which -a bash
/bin/bash
/usr/bin/bash
/usr/bin/bash

Since /usr/bin is now in my $PATH twice, which -a finds the same bash twice.

  • 2
    To expand: The -a option reports ALL matches in your PATH. That's what it's for. If, as noted, your $PATH references the same place more than once, or the same executable is in more than one place, it'll show up multiple times with -a (but not when omitting that option). – SuperMagic Mar 6 '13 at 14:55
2

As the hint says, and quoting from the manual page, "Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash(1)." As for the -a option, it lists all the executables by that name found in $PATH.

1

Take a look at your path:

echo $PATH

There are duplicate entries in your path (or ruby is installed several times in different locations).

1

Try

whereis -b ruby

If you are getting the same output, then the problem is in your PATH.

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.