在 zsh 中放置 $PATH 变量断言的位置? [英] Where to place $PATH variable assertions in zsh?
问题描述
我喜欢 zsh
,但我不确定将我的 $PATH
和其他变量断言放在哪里?我发现它们分散在文件.zshrc
.zprofile
.bashrc
.bash_profile
之间,有时会翻倍.
I love zsh
, but I am not sure where to place my $PATH
and other variable assertions? I find that they are scattered between the files .zshrc
.zprofile
.bashrc
.bash_profile
, and sometimes doubled.
我意识到在 bash
文件中包含任何内容并没有多大意义,因为我正在使用 zsh
,但是 我到底应该放在哪里我的 rvm
、python
、node
等添加到我的 $PATH
?
I realize that having anything inside the bash
files doesn't make much sense seeing as I'm using zsh
, but where exactly should I be placing my rvm
, python
, node
etc additions to my $PATH
?
是否有我应该使用的特定文件(即 .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?
推荐答案
tl;dr version: use ~/.zshrc
tl;dr version: use ~/.zshrc
和阅读手册页以了解它们之间的区别:
And read the man page to understand the differences between:
~/.zshrc
、~/.zshenv
和 ~/.zprofile
.
<小时>
关于我的评论
Regarding my comment
In my comment attached to the answer kev gave, I said:
这似乎不正确 - 我能找到的任何 zsh 文档中都没有列出/etc/profile.
This seems to be incorrect - /etc/profile isn't listed in any zsh documentation I can find.
事实证明这部分不正确:/etc/profile
可能来自 zsh
.然而,这仅在 zsh
被作为 sh
或 ksh
调用"时发生;在这些兼容模式下:
This turns out to be partially incorrect: /etc/profile
may be sourced by zsh
. However, this only occurs if zsh
is "invoked as sh
or ksh
"; in these compatibility modes:
不执行通常的 zsh 启动/关闭脚本.登录 shell 源/etc/profile 后跟 $HOME/.profile.如果在调用时设置了 ENV 环境变量,则 $ENV 来自配置文件脚本之后.ENV 的值在被解释为路径名之前经过参数扩展、命令替换和算术扩展.[man zshall,兼容性"].
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"].
在登录时,Zsh 按以下顺序获取以下文件:
/etc/profile
此文件在登录时由所有 Bourne 兼容的 shell 提供
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(/etc/中设置的
不要进入我的 zsh 会话).$PATH
中的路径profile
This implys that /etc/profile
is always read by zsh
at login - I haven't got any experience with the Arch Linux project; the wiki may be correct for that distribution, but it is not generally correct. The information is incorrect compared to the zsh manual pages, and doesn't seem to apply to zsh on OS X (paths in $PATH
set in /etc/profile
do not make it to my zsh sessions).
我应该将 rvm、python、node 等添加到 $PATH 的确切位置放在哪里?
where exactly should I be placing my rvm, python, node etc additions to my $PATH?
通常,我会从 ~/.zshrc
导出我的 $PATH
,但值得一读 zshall 手册页,特别是STARTUP/SHUTDOWN FILES"部分 - ~/.zshrc
是为 interactive 外壳,它可能适合也可能不适合您的需要 - 如果您希望为您调用的每个 zsh
外壳使用 $PATH
(interactive
而不是,login
和不是,等等),那么 ~/.zshenv
是更好的选择.
Generally, I would export my $PATH
from ~/.zshrc
, but it's worth having a read of the zshall man page, specifically the "STARTUP/SHUTDOWN FILES" section - ~/.zshrc
is read for interactive shells, which may or may not suit your needs - if you want the $PATH
for every zsh
shell invoked by you (both interactive
and not, both login
and not, etc), then ~/.zshenv
is a better option.
是否有我应该使用的特定文件(即我的安装中当前不存在的 .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?
启动时读取了一堆文件(检查链接的 man
页面),这是有原因的 - 每个文件都有其特定的位置(每个用户的设置,用户特定的设置)、登录 shell 的设置、每个 shell 的设置等).
不用担心 ~/.zshenv
不存在 - 如果你需要它,制作它,它会被读取.
There's a bunch of files read on startup (check the linked man
pages), and there's a reason for that - each file has it's particular place (settings for every user, settings for user-specific, settings for login shells, settings for every shell, etc).
Don't worry about ~/.zshenv
not existing - if you need it, make it, and it will be read.
.bashrc
和 .bash_profile
不会被 zsh
读取,除非您明确地从 获取它们>~/.zshrc
或类似的;bash
和 zsh
之间的语法不总是兼容的..bashrc
和 .bash_profile
都是为 bash
设置而设计的,而不是 zsh
设置.
.bashrc
and .bash_profile
are not read by zsh
, unless you explicitly source them from ~/.zshrc
or similar; the syntax between bash
and zsh
is not always compatible. Both .bashrc
and .bash_profile
are designed for bash
settings, not zsh
settings.
这篇关于在 zsh 中放置 $PATH 变量断言的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!