Why does bash run a different version of `command' than `which command' says it will?

Why does bash run a different version of `command' than `which command' says it will?


On many systems, `which' is actually a csh script that assumes
you're running csh. In tcsh, `which' and its cousin `where'
are builtins. On other Unix systems, `which' is a perl script
that uses the PATH environment variable.

The csh script version reads the csh startup files from your
home directory and uses those to determine which `command' will
be invoked. Since bash doesn't use any of those startup files,
there's a good chance that your bash environment differs from
your csh environment. The bash `type' builtin does everything
`which' does, and will report correct results for the running
shell. If you're really wedded to the name `which', try adding
the following function definition to your .bashrc:

which()
{
builtin type "$@"
}

If you're moving from tcsh and would like to bring `where' along
as well, use this function:

where()
{
builtin type -a "$@"
}



Home FAQ