bash 为每个终端加载 .bash_profile
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34352907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Load .bash_profile for every terminal
提问by Kevin
I set up some aliases in my .bash_profileon my Max OS X. It works but when I'm opening a new tab I always have to load my .bash_profilefile with this command:
我在Max OS X 上的.bash_profile 中设置了一些别名。它可以工作,但是当我打开一个新选项卡时,我总是必须使用以下命令加载我的.bash_profile文件:
source ~/.bash_profile
How can I make it work for every terminal I'm opening, even if I'm restarting my Mac or Linux computer?
即使我正在重新启动 Mac 或 Linux 计算机,我怎样才能使它适用于我打开的每个终端?
回答by
The files executed at the start may be several, usually ~/.bashrc for interactive, non-login shells. The kind I assume you are using.
开始时执行的文件可能有几个,通常是 ~/.bashrc 用于交互式非登录 shell。我假设你正在使用的那种。
If so, create an ~/.bashrc
file and source ~/.bash_profile
in it:
如果是这样,请在其中创建一个~/.bashrc
文件和源~/.bash_profile
:
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
This web site has a lot of informationabout this.
Study this image, as it is a condensed guide
研究这个图像,因为它是一个浓缩的指南
If you do need to find out exactly which file is being executed, take a look at this web page. It has a lot of specific tests to find out what file is setting what.
如果您确实需要确切地找出正在执行的文件,请查看此网页。它有很多特定的测试来找出哪个文件正在设置什么。
Specific for Mac-OS (which is an exception and loads ~/.bash_profile) do as is recomended in the site linked in this answerAFTER you confirm that your bash is doing as explained there.
特定于 Mac-OS(这是一个例外并加载 ~/.bash_profile),在您确认您的 bash 按照那里的说明进行操作后,按照本答案中链接的站点中的建议进行操作。
回答by Mehdico
If you use oh my zsh, you can add source ~/.bash_profileline at the end of .zshrcfile at the following path: /Users/YOUR USER NAME/.zshrc
如果您使用oh my zsh,则可以在以下路径的.zshrc文件末尾添加source ~/.bash_profile行:/Users/YOUR USER NAME/.zshrc
Note that this file is hidden. You can press CMD + SHIFT + .in Finder to see it, Or just open it in default text editor with the following command from terminal:
open /Users/YOUR USER NAME/.zshrc
请注意,此文件是隐藏的。您可以按CMD + SHIFT + 。在 Finder 中查看它,或者只是在默认文本编辑器中使用终端中的以下命令打开它:
open /Users/YOUR USER NAME/.zshrc