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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:06:50  来源:igfitidea点击:

How to fix Terminal not loading ~/.bashrc on OS X Lion

macosbashterminalosx-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 .bashrcis loaded via relative and not absolute path, because if I do source ~/.bashrc, everything works smoothly.

看起来.bashrc是通过相对而不是绝对路径加载的,因为如果我这样做source ~/.bashrc,一切都会顺利进行。

loaded bashrc

加载 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 ~/.bashrcvia absolute path, and not relative?

但是问题仍然存在,如何~/.bashrc通过绝对路径而不是相对路径进行终端加载?

回答by ckruse

Terminal opens a login shell. This means, ~/.bash_profilewill get executed, ~/.bashrcnot.

终端打开一个登录外壳。这意味着,~/.bash_profile将被执行,~/.bashrc而不是。

The solution on most systems is to "require" the ~/.bashrcin the ~/.bash_profile: just put this snippet in your ~/.bash_profile:

大多数系统上的解决方案是“规定”中~/.bashrc~/.bash_profile:只是把这个片段在~/.bash_profile

[[ -s ~/.bashrc ]] && source ~/.bashrc

回答by scorpiodawg

Renaming .bashrcto .profile(or soft-linking the latter to the former) should also do the trick. See here.

重命名.bashrc.profile(或将后者软链接到前者)也应该可以解决问题。见这里

回答by Keith Thompson

I have the following in my ~/.bash_profile:

我有以下内容~/.bash_profile

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

If I had .bashrcinstead of ~/.bashrc, I'd be seeing the same symptom you're seeing.

如果我有.bashrc而不是~/.bashrc,我会看到与您看到的相同的症状。