每次打开终端时都需要重新加载 bash 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10209031/
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
Need to reload bash every time i open terminal?
提问by Alex
Every time I open terminal, I don't seem to have my bash profile loaded.
By this, I mean if I type:
每次打开终端时,我似乎都没有加载我的 bash 配置文件。
我的意思是,如果我输入:
git
node
brew
git
节点
酿造
etc... i get "command not found"
等等......我得到“找不到命令”
If I run:
如果我运行:
source ~/.bashrc
源 ~/.bashrc
Then it fixes the issue. I seem to have to do this on each restart
然后它解决了这个问题。我似乎每次重新启动时都必须这样做
Any way to make it do this automatically?
有什么办法让它自动做到这一点?
回答by Michael Wild
Presumably this is Mac OS X, right? The reason you see this behaviour is that Terminal.app creates a login shell, which only sources ~/.bash_profileor ~/.profileif the former doesn't exist. To solve your problem, either:
想必这是 Mac OS X 吧?您看到这种行为的原因是 Terminal.app 创建了一个登录 shell,它只提供源,~/.bash_profile或者~/.profile如果前者不存在。要解决您的问题,请执行以下任一操作:
- Source your
~/.bashrcfrom your~/.bash_profileor~/.profile - Put your commands in
~/.bash_profileor~/.profileinstead of~/.bashrc - Configure Terminal.app to create a interactive non-login shell.
- 源您
~/.bashrc从您的~/.bash_profile或~/.profile - 将您的命令放入
~/.bash_profile或~/.profile代替~/.bashrc - 配置 Terminal.app 以创建交互式非登录 shell。
回答by yazu
Add
添加
source ~/.bashrc
in ~/.profileor ~/.bash_profile
在~/.profile或~/.bash_profile

