本文介绍了哪里将$ PATH变量断言放在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.

我意识到在使用zsh时在bash文件中包含任何内容并没有多大意义,但是我应该将rvmpythonnode我的$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 ),或者我正在使用的其中一个文件,或者甚至有关系吗? /p>

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版本:使用~/.zshrc

tl;dr version: use ~/.zshrc

阅读手册页来了解以下内容之间的区别:

And read the man page to understand the differences between:


关于我的评论

在回答 kev给的答案的评论中,我说:


Regarding my comment

In my comment attached to the answer kev gave, I said:

这在某种程度上是不正确的:/etc/profile 可能来自zsh. 但是,只有在zsh被作为shksh调用"时,才会发生这种情况;在以下兼容模式下:

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:

ArchWiki ZSH链接说:

这意味着/etc/profile在登录时始终被zsh读取 -我对Arch Linux项目没有任何经验. Wiki对于该发行版可能是正确的,但通常不是是正确的.与zsh手册页相比,信息 不正确,并且似乎不适用于OS X上的zsh(在/etc/profile中设置的$PATH中的路径不会使其进入我的zsh会话) .

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


通常,我会从~/.zshrc导出我的$PATH,但是值得阅读 zshall 手册页,特别是"STARTUP/SHUTDOWN FILES"(启动/关闭文件)部分-~/.zshrc是为 interactive 外壳读取的,它可能适合也可能不适合您的需要-如果您想要$PATH对于您调用的每个zsh shell(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.

启动时读取了大量文件(请检查链接的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或类似来源获得它们; bashzsh之间的语法始终不兼容. .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.

这篇关于哪里将$ PATH变量断言放在zsh中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:01