Calling binary in search path vs. calling it explicitely
First of all I am not sure if this question fits best on SO, it could also be appropriate on Superuser.
I've been noticing a strange behavior lately. Consider the following:
$ g++ -v
g++: error trying to exec '/usr/local/bin/i686-apple-darwin10-g++-4.2.1': execvp: No such file or directory
$ which g++
/usr/local/bin/g++
$ /usr/local/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin10.7.0/4.6.0/lto-wrapper
Target: x86_64-apple-darwin10.7.0
Configured with: ../gcc-4.6.0/configure --enable-languages=fortran,c++
Thread model: posix
gcc version 4.6.0 (GCC)
This question is le开发者_运维问答ss about the errors (gcc 4.6 on Mac OS was bound to cause troubles), instead I feel that something does not match the mental model I had how a search path works. Could somebody explain that behavior to me?
One possible explanation is an alias for g++:
x@y:~$alias g++="/usr/bin/doesnotexist"
x@y:~$g++
-bash: /usr/bin/doesnotexist: No such file or directory
x@y:~$which g++
/usr/bin/g++
x@y:~$/usr/bin/g++
i686-apple-darwin10-g++-4.2.1: no input files
So I'd check for aliases first (simply type "alias" without any arguments).
精彩评论