How can I have my shell always start in a certain directory that is not my home directory
I've tried putting
cd /Users/my_name/my_directory/structure
in both .bashrc
and .bash_login
but neither works, i.e. when I open a new terminal window I am in my home (/Users/my_name/) directory.
No error messages, just not cd'd into the directory as hoped when starting a new terminal window.
As Gerry mentioned, .bashrc
is not read by login shells. New tabs are login shells by default in Terminal and iTerm 2. .bash_login
is only read if there's no .bash_profile
.
You could also add a cd
command to .bash_profile
.
First of all, if you are not using iTerm2 already, I suggest you download this free software as a replacement for Terminal.app.
Among many other extra features, in iTerm Preferences, you can configure the default working directory for new shells. You'll find these settings in Profiles - General.
The advantage here is that you can set different behaviors for opening a new window vs opening a new tab or even creating a new split pane. I personally like staying in the current working directory when adding a split pane, for example.
You could do it in your startup script as well (though I find the iTerm solution cleaner, or at least more flexible), but then I advise you to use ~/.bash_profile
instead.
~/.bashrc
is not automatically sourced when opening a new shell window, and ~/.bash_login
is only sourced if no ~/.bash_profile
is present.