bash 如何修复终端未在 OS X Lion 上加载 ~/.bashrc
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7780030/
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
How to fix Terminal not loading ~/.bashrc on OS X Lion
提问by Jakub Arnold
Whenever I open a new tab in Terminal using Cmd+ T, it opens bash in the same directory, as the previous tab. This works fine when I'm in the ~
directory, but if I'm anywhere else, I get an error loading .bashrc
每当我使用Cmd+在终端中打开一个新选项卡时T,它都会在与上一个选项卡相同的目录中打开 bash。当我在~
目录中时这工作正常,但如果我在其他任何地方,我会收到错误加载.bashrc
Last login: Sat Oct 15 21:10:00 on ttys002
-bash: .bashrc: No such file or directory
Jakub-Arnolds-MacBook-Pro:projects darth$
It looks like .bashrc
is loaded via relative and not absolute path, because if I do source ~/.bashrc
, everything works smoothly.
看起来.bashrc
是通过相对而不是绝对路径加载的,因为如果我这样做source ~/.bashrc
,一切都会顺利进行。
I think this is a OS X Lion related problem, because before the upgrade from Snow Leopard, I didn't have the same issue. But that might be caused by Terminal always opening at ~
, I don't remember if it tried to open the same directory.
我认为这是与 OS X Lion 相关的问题,因为在从 Snow Leopard 升级之前,我没有遇到同样的问题。但这可能是由于终端总是打开~
,我不记得它是否尝试打开同一目录。
However the question remains the same, how can I make Terminal load ~/.bashrc
via absolute path, and not relative?
但是问题仍然存在,如何~/.bashrc
通过绝对路径而不是相对路径进行终端加载?
回答by ckruse
Terminal opens a login shell. This means, ~/.bash_profile
will get executed, ~/.bashrc
not.
终端打开一个登录外壳。这意味着,~/.bash_profile
将被执行,~/.bashrc
而不是。
The solution on most systems is to "require" the ~/.bashrc
in the ~/.bash_profile
: just put this snippet in your ~/.bash_profile
:
大多数系统上的解决方案是“规定”中~/.bashrc
的~/.bash_profile
:只是把这个片段在~/.bash_profile
:
[[ -s ~/.bashrc ]] && source ~/.bashrc
回答by scorpiodawg
回答by Keith Thompson
I have the following in my ~/.bash_profile
:
我有以下内容~/.bash_profile
:
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
If I had .bashrc
instead of ~/.bashrc
, I'd be seeing the same symptom you're seeing.
如果我有.bashrc
而不是~/.bashrc
,我会看到与您看到的相同的症状。