Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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$  

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

loaded 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.

However the question remains the same, how can I make Terminal load ~/.bashrc via absolute path, and not relative?

like image 572
Jakub Arnold Avatar asked Oct 15 '11 19:10

Jakub Arnold


People also ask

Where is ~/ bashrc in Mac?

bashrc file typically lives at ~/. bashrc . For my Mac for example that is /home/lcollado/. bashrc .

Does macOS have bashrc?

On macOS /etc/profile sets the default PATH with the path_helper tool and then source s /etc/bashrc which (you guessed) would be the central file for all users that is executed for non-login interactive shells. For macOS Terminal.


2 Answers

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

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 
like image 119
ckruse Avatar answered Oct 05 '22 09:10

ckruse


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

like image 33
scorpiodawg Avatar answered Oct 05 '22 11:10

scorpiodawg