4

Every time I add a new alias in my .bash_profile file, I found that I must do the command . .bash_profile in my terminal to make it work.

Why does the alias not work automatically?

1 Answers1

5

First of all, you should put the aliases in ~/.bashrc and not in ~/.bash_profile.

Next the explanation: the aliases are read and make available only when the file that contain them is read. So the requirement to source that file.

enzotib
  • 93,831
  • Thank you, why do the aliases go in ~/.bashrc? They seem to work both ways. Also, what is sourcing a file? – David Faux Mar 04 '12 at 18:27
  • 2
    @DavidFaux: because ~/bashrc is read for interactive shells, and aliases are only useful in interactive shells. "Sourcing" refers to read and execute a script in the current shell (as opposed to a subshell). To source a script you use the dot . or the source builtin command. – enzotib Mar 04 '12 at 18:32
  • 1
    Source means to read from a file. So your bash shell reads, or sources, your configuration from .bashrc, and other files. As to where to place your alises, and environmental variables, it depends on if you want to run an interactive shell (login / terminal) or use bash in a script (non-interactive). See http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html and http://linuxcommand.org/ – Panther Mar 04 '12 at 18:33