Mac Gnu-Screen doesn't load default .bash_profile

The .bash_profile file (and .profile file as well) is loaded for login shells, non-login shells use .bashrc (no _ symbol). There is a line in the .screenrc file that tells screen what shell to spawn when starting a screen window (when not launching a specific program as the window application). In my .screenrc file, this is as such (including comments as well):

# shell:  Default process started in screen's windows.
# Makes it possible to use a different shell inside screen
# than is set as the default login shell.
# If begins with a '-' character, the shell will be started as a login shell.
  shell -$SHELL

Check your .screenrc file and verify that the shell line has the dash in front of it. By having that dash symbol and forcing a login shell, you'll get your .bash_profile sourced. The $SHELL variable in my .screenrc is using the shell value as provided by the shell that launches screen (generally for me it's bash).

In case you're wondering, the biggest difference that I've been able to discover between login versus non-login shells is that a non-login shell is normally what's invoked for executing scripts.


Sourcing .bash_profile is actually something different that the Mac terminal app does that most terminal apps don't do. Screen does read ~/.bashrc however, each time you spawn a new shell.

If you rename your ~/.bash_profile to ~/.bashrc (with no underscore between bash and rc, as in your question), then it will be sourced.

My preferred strategy however is to put all of my settings in the bashrc, and then source it from bash_profile like this:

[ -f .bashrc ] && . .bashrc

Tags:

Gnu Screen

Mac