9

which -a ruby gives me

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

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

Kowh
  • 580
Aswini
  • 101
  • 2

4 Answers4

10

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.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • 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 06 '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.

schaiba
  • 7,631
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).

Alexander
  • 9,850
1

Try

whereis -b ruby

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

TPS
  • 2,481