Ken Cunningham wrote:
what you see is difficult to explain, unless the PATH changed between the two
tests.
if
'which gcc' gives /opt/local/bin/gcc
then
gcc --version
should give exactly the same as
/opt/local/bin/gcc --version
Not necessarily. Shells cache command locations, so if 'gcc' was run
prior to the creation of /opt/local/bin/gcc, subsequently invocations
will continue to run the previously found gcc. Running 'hash -r' or
starting a new shell will give you an empty cache and thus set things right.
The 'which' command doesn't know about the shell's cache state; it only
looks at the current PATH. This is why 'type' often helps to understand
what's going on in these situations, as Richard hinted.
- Josh