zsh PATH 的奇怪行为 [英] Weird behaviour with zsh PATH
问题描述
我只是鼓励今天 zsh 出现一个奇怪的问题.
I just encourage a weird problem with zsh today.
我的环境是 Mac OS X Yosemite,zsh 5.0.5 (x86_64-apple-darwin14.0)
My environment is Mac OS X Yosemite, zsh 5.0.5 (x86_64-apple-darwin14.0)
在 .zshrc 中,我手动将 PATH 变量设置为类似
In .zshrc, I have manually set the PATH variable to something like
export PATH="$PATH:~/.composer/vendor/bin"
在终端中尝试echo $PATH
,结果如预期(包含~/.composer/vendor/bin
).然后尝试从 ~/.composer/vendor/bin
执行一个二进制文件,它总是会返回zsh: command not found"错误.
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.
尝试切换到 bash,echo $PATH
也符合预期,结果与 zsh shell 相同.尝试从 ~/.composer/vendor/bin
执行一个二进制文件,没有发现问题.似乎 PATH var 在 bash shell 上运行良好.
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.
我的 zsh shell 有什么问题?
What's wrong with my zsh shell?
谢谢
推荐答案
尝试使用 $HOME
而不是 ~
.在许多情况下,shell 不会在您期望的情况下扩展 ~
,通常最好使用 $HOME
.~
实际上只是作为交互式使用的捷径.(我能回忆起首选 ~
的唯一情况是在 .gitalias 中,其中 ~ 被扩展而变量没有.)
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.)
这篇关于zsh PATH 的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!