Why does zsh ignore the PATH entry order?
By default zsh
hashes locations of commands the first time they are executed. When executing it a second time the hashed path is used. To refresh the hash table run
rehash
or
hash -r
This should happen automatically every time you change PATH
and its main use is, when new executables are added to directories already in PATH
.
Note: the following might be overkill for the specific use case. But it also does solve the issue and might be of interest for slightly different use cases.
If you do not care about the (probably negligible) performance hit, you can disable hashing of commands by disabling the HASH_CMDS
option:
setopt nohashcmds
While zsh
will still be using the hash table, it will not automatically add every command. So, unless a command is entered to the hash table by other means, zsh
will check PATH
for the command every time.
This might still lead to problems, if the option CORRECT
is set. As this does set the hash table in order to provide spelling correction, but will not necessarily refresh it when PATH
changes. In order to refresh the table automatically, you can use the precmd
hook which is executed each time before the prompt is printed.
autoload -Uz add-zsh-hookauto_rehash () { rehash}add-zsh-hook precmd auto_rehash
zsh does not skip PATH entries. It does, however, give priority of alias and shell functions. This doesn't apply to your case, because if you had any of those, where
would have listed this too.
In your case, if the where
and the ocamlc
command have been executed in the same shell, and in that order, you can be pretty sure that ocamlc
executes /home/choeger/ueb/uebb/amsun-integration/Runtime/test_src/../../opam/4.02.3/bin/ocamlc
. Did you try running Ocam explicitly via this absolute path? I bet you will get the same output.
BTW, type -a
would give, in general, a bit more detailed information than where
.