我喜欢 zsh
,但我不确定将我的 $PATH
和其他变量断言放在哪里?我发现它们分散在文件 .zshrc
.zprofile
.bashrc
.bash_profile
之间,有时会加倍。
我意识到,在 bash
文件中包含任何内容并没有多大意义,因为我正在使用 zsh
,但是我到底应该将其放置在哪里我的 rvm
、python
、node
等添加到我的 $PATH
中?
是否有我应该使用的特定文件(即 .zshenv
,它当前不存在于我的安装中),我当前正在使用的文件之一,或者这还重要吗?
最佳答案
tl;dr版本:使用~/.zshrc
和read the man page了解之间的差异:
<小时/>
~/.zshrc
,~/.zshenv
and~/.zprofile
.
关于我的评论
在我附加到答案的评论中kev gave ,我说:
This seems to be incorrect - /etc/profile isn't listed in any zsh documentation I can find.
这被证明是部分不正确的:/etc/profile
可能由zsh
获取。 但是,只有当 zsh
被“作为 sh
或 ksh
调用”时才会发生这种情况;在这些兼容模式下:
The usual zsh startup/shutdown scripts are not executed. Login shells source /etc/profile followed by $HOME/.profile. If the ENV environment variable is set on invocation, $ENV is sourced after the profile scripts. The value of ENV is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a pathname. [man zshall, "Compatibility"].
At login, Zsh sources the following files in this order:
/etc/profile
This file is sourced by all Bourne-compatible shells upon login
这意味着 /etc/profile
在登录时zsh
总是读取 - 我没有任何使用 Arch Linux 的经验项目; wiki 对于该发行版可能是正确的,但通常不是正确的。与 zsh 手册页相比,该信息不正确,并且似乎不适用于 OS X 上的 zsh($PATH
中的路径在 /etc/中设置) profile
不会进入我的 zsh session )。
解决这个问题:
where exactly should I be placing my rvm, python, node etc additions to my $PATH?
通常,我会从 ~/.zshrc
导出我的 $PATH
,但值得一读 zshall手册页,特别是“启动/关闭文件”部分 - ~/.zshrc
是针对交互式 shell 读取的,它可能适合也可能不适合您的需求 - 如果您想要$PATH
用于您调用的每个 zsh
shell(interactive
和非 login
等) ,那么 ~/.zshenv
是一个更好的选择。
Is there a specific file I should be using (i.e. .zshenv which does not currently exist in my installation), one of the ones I am currently using, or does it even matter?
启动时会读取一堆文件(检查链接的手册页),这是有原因的 - 每个文件都有其特定的位置(每个用户的设置、特定于用户的设置) 、登录 shell 的设置、每个 shell 的设置等)。
不用担心 ~/.zshenv
不存在 - 如果您需要它,创建它,它将被读取。
.bashrc
和 .bash_profile
不会被 zsh
读取,除非您明确从 获取它们>~/.zshrc
或类似的; bash
和 zsh
之间的语法并不始终兼容。 .bashrc
和 .bash_profile
都是为 bash
设置而不是 zsh
设置而设计的。
关于macos - 在 zsh 中哪里放置 $PATH 变量断言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10574684/