4

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?

enzotib
  • 93,831
mushfiq
  • 163
  • 1
    Take a look here: http://askubuntu.com/questions/121073/why-bash-profile-is-not-getting-sourced-when-opening-a-terminal There is a good explanation. –  Jul 11 '13 at 15:39

2 Answers2

6

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.

enzotib
  • 93,831
  • 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 07:57
1

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

ed.
  • 264