如何修复终端未在 OS X Lion 上加载 ~/.bashrc [英] How to fix Terminal not loading ~/.bashrc on OS X Lion

查看:17
本文介绍了如何修复终端未在 OS X Lion 上加载 ~/.bashrc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我使用 Cmd + T 在终端中打开一个新选项卡时,它都会在与上一个选项卡相同的目录中打开 bash.当我在 ~ 目录中时,这工作正常,但如果我在其他任何地方,我会在加载 .bashrc

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

Last login: Sat Oct 15 21:10:00 on ttys002
-bash: .bashrc: No such file or directory
Jakub-Arnolds-MacBook-Pro:projects darth$ 

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

It looks like .bashrc is loaded via relative and not absolute path, because if I do source ~/.bashrc, everything works smoothly.

我认为这是与 OS X Lion 相关的问题,因为在从 Snow Leopard 升级之前,我没有遇到同样的问题.但这可能是终端总是在~打开造成的,我不记得它是否尝试打开相同的目录.

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.

但是问题还是一样,我怎样才能通过绝对路径而不是相对路径让终端加载~/.bashrc?

推荐答案

终端打开登录 shell.这意味着,~/.bash_profile 会被执行,~/.bashrc 不会.

Terminal opens a login shell. This means, ~/.bash_profile will get executed, ~/.bashrc not.

大多数系统上的解决方案是在 ~/.bash_profile 中要求"~/.bashrc:只需将此代码段放入您的 ~/.bash_profile:

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

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

这篇关于如何修复终端未在 OS X Lion 上加载 ~/.bashrc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆