Weird behaviour with zsh PATH

前端 未结 2 1739
谎友^
谎友^ 2021-01-25 05:29

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

相关标签:
2条回答
  • 2021-01-25 06:08

    Type rehash to pick-up $PATH changes.

    From the zsh user guide:

    The way commands are stored has other consequences. In particular, zsh won't look for a new command if it already knows where to find one. If I put a new ls command in /usr/local/bin in the above example, zsh would continue to use /bin/ls (assuming it had already been found). To fix this, there is the command rehash, which actually empties the command hash table, so that finding commands starts again from scratch. Users of csh may remember having to type rehash quite a lot with new commands: it's not so bad in zsh, because if no command was already hashed, or the existing one disappeared, zsh will automatically scan the path again; furthermore, zsh performs a rehash of its own accord if $path is altered. So adding a new duplicate command somewhere towards the head of $path is the main reason for needing rehash.

    EDIT However @WilliamPursell could be onto something with his comment:

    note that "composer" != ".composer"

    0 讨论(0)
  • 2021-01-25 06:09

    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.)

    0 讨论(0)
提交回复
热议问题