I need to run a script when I login and logout in my Ubuntu.
I tried to put the script in my ~/.bash_login
but it didn't work.
Is there a better location where I can run my script?
My script is located in /home/gsd/script/login.sh
and it's executable.
edit:
my script runs when i type: /home/gsd/script/login.sh
and it set with +x
now, i only have: touch /home/gsd/test.txt
in the ~/.bash_login
to test.
the file test.txt is never created
edit 2:
gsd@laptop:~$ ll ~/.bash*
-rw------- 1 gsd gsd 38639 2012-01-25 17:25 .bash_history
-rw-r--r-- 1 gsd gsd 29 2012-01-25 15:22 .bash_login
-rw-r--r-- 1 gsd gsd 220 2011-11-03 19:22 .bash_logout
-rw-r--r-- 1 gsd gsd 3136 2011-11-04 08:00 .bashrc
Best Answer
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_login
are 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.The GNU Bash Reference Manual version 4.1: Bash Startup Files says:
Also see this question on superuser, and this Bash howto (Don't be deterred by the freeunix.dyndns.org:8088 address--- it's still a good quality manual and I have used it for years).
Update, since you say you don't have a .bash_profile.
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
.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