问题
I just encourage a weird problem with zsh today.
My environment is Mac OS X Yosemite, zsh 5.0.5 (x86_64-apple-darwin14.0)
In .zshrc, I have manually set the PATH variable to something like
export PATH="$PATH:~/.composer/vendor/bin"
Try echo $PATH in terminal, the result is as expected (contained ~/.composer/vendor/bin). Then try executing a binary from ~/.composer/vendor/bin, It'll always return me "zsh: command not found" error.
Try switching to bash, echo $PATH is also as expected, have the same result as zsh shell.
Try executing a binary from ~/.composer/vendor/bin, no problem found. Seem the PATH var is acting well on the bash shell.
What's wrong with my zsh shell?
Thanks
回答1:
Try using $HOME instead of ~.  In many situations, shells do not expand ~ when you expect them to and it is usually better to use $HOME.  ~ is really only intended to be a short cut for interactive use.  (The only case I can recall where ~ was preferred was in a .gitalias, where ~ was expanded and variables were not.)
回答2:
Type rehash to pick-up $PATH changes.
From the zsh user guide:
The way commands are stored has other consequences. In particular,
zshwon't look for a new command if it already knows where to find one. If I put a newlscommand in/usr/local/binin the above example, zsh would continue to use/bin/ls(assuming it had already been found). To fix this, there is the commandrehash, which actually empties the command hash table, so that finding commands starts again from scratch. Users ofcshmay remember having to typerehashquite a lot with new commands: it's not so bad inzsh, because if no command was already hashed, or the existing one disappeared,zshwill automatically scan the path again; furthermore,zshperforms a rehash of its own accord if$pathis altered. So adding a new duplicate command somewhere towards the head of$pathis the main reason for needing rehash.
EDIT However @WilliamPursell could be onto something with his comment:
note that "composer" != ".composer"
来源:https://stackoverflow.com/questions/29820315/weird-behaviour-with-zsh-path