It is not necessary to chmod +x .bash_login (set the executable bit on .bash_login). The Bash manual is a bit confusing in this area, but Bash does not eXecute .bash_login like a shell script. It does read the file and then executes the commands within it (You can do something similar by running source ~/.bash_login).
–
Stefan LasiewskiJan 25 '12 at 19:31

3 Answers
3

If .bash_profile exists, then Bash will not read .bash_login (or .profile). This annoying feature is described in some versions of the Bash manual, but not all.

.bash_profile and .bash_loginare analogous, so I recommend you put your commands in .bash_profile, because it's is commonly used and .bash_login is relatively unknown. Also consider putting your commands in .bashrc instead of .bash_profile. The manual describes difference between "interactive non-login shell" and "interactive login shell", so be sure to read that section.

It sounds like you are not using what's called a "interactive non-login shell" (See the Bash manual for a detailed description).

To test this, add something like the following each file: .bashrc, .bash_profile and .bash_login.

echo "DEBUG: I am .bashrc"
echo "DEBUG: I am .bash_profile"

Then log out and log in again. When you log in, I bet you will only see the phrase "DEBUG: I am .bashrc" but not "I am .bash_profile". If so, it means you are a "interactive non-login shell", which simply means that Bash will call .bashrc but not .bash_profile. For information why these dotfiles are the way they are, see @Andrejs Cainikovs's post below and http://mywiki.wooledge.org/DotFiles

Make sure the script you want to run is executable. Run chmod +x scriptname to do that. Also make sure the script starts with the correct shebang (#!/bin/bash for shell scripts). Lastly, use all full paths when executing it, e.g., /usr/bin/echo instead of echo just incase the environment that your script will execute in is not identical to the one you are used to.

Bash only looks for .bash_login or .profile files if it is executed as interactive login shell. When it is executed as interactive non-login shell it reads .bashrc.
Commonly it is the second case, i.e when you run gnome-terminal bash is run as non-login shell.

This clearly states that if you are booting into Gnome, .bash_login will not be executed. But if you lower runlevel to boot directly to bash, the same file will be executed upon succesfull login.
I assume .bash_login will be executed in case of remote SSH connections as well.