Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My .bash_profile is like below:

alias l='ls -l'
alias p='pwd'
alias sites='cd /home/caveman/sites'
alias time_card='cd /home/caveman/sites/time-card/time-card'
alias ping='ping google.com'
alias bash_profile='gedit /home/caveman/.bash_profile'
alias webroot='cd /var/www'

every time I log into my machine I need to run the source .bash_profile to make all the alias available.

Can you guys figure out where is the problem is?

share|improve this question
1  
Take a look here: askubuntu.com/questions/121073/… There is a good explanation. –  user174388 Jul 11 '13 at 15:39
add comment

2 Answers

up vote 5 down vote accepted

The ~/.bash_profile is only read in login session.

Also, having a ~/.bash_profile prevents the sourcing of ~/.profile, that is the preferred file to use for login shell in the bash configuration for Ubuntu.

When you log in the Display Manager (I suppose GDM), the ~/.profile is read by default (I don't know if GDM follows bash rules and read ~/.bash_profile instead, if exists).

Even if ~/.bash_profile were read from GDM, aliases are not inherited, so the shell you have in a graphics terminal (that is not a login shell) cannot see them.

The solution is: put your aliases in ~/.bashrc, and use aliases only for very simple things, otherwise use functions.

The file ~/.bashrc is read by non-login interactive shells, and is sourced in ~/.profile, so that its content is also available in login shells.

share|improve this answer
    
I see,in MAC OSX the bash profile works for alias as why I tried same in ubuntu,thanks for your navigation :) –  mushfiq Sep 23 '11 at 7:57
add comment

You could just add the aliases to ~/.bash_aliases instead

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.