Search code examples
macosmacos-mojave

which command doesn't work on my computer


In the past, we 'which' command to get the info of the relevant software on our computer, Like:

which python
which git 

But now it seems don't work on my MacOS Mojave. Is there anything wrong with my setting?

New edition: The result will turn out to be like this

AA:~ AA$ which python
/usr/bin/which: illegal option -- -
usage: which [-as] program ...

New edition2:

AA:~ AA$ type --all which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
which is /usr/bin/which

AA:~ AA$ type -all python
python is /Users/AA/anaconda3/bin/python
python is /Users/AA/anaconda/bin/python
python is /usr/bin/python
AA:~ AA$

Solution

  • The alias is what causes the error message. Apparently the alias definition is simply erroneous for your system. It's not clear what defined this alias or why; it seems wrong on several levels, so I doubt it's part of the standard install.

    You can remove the alias with unalias which; but I'm guessing it's defined in one of your startup files, and should be removed from there - after this point, it should be gone for good the next time you log in.

    But anyway, you should not be using which - it's better to accustom yourself to the POSIX standard command type. It was introduced specifically to replace which but it's apparently still hard to eradicate the old command from people's minds.