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.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
    
Thank you, why do the aliases go in ~/.bashrc? They seem to work both ways. Also, what is sourcing a file? –  David Faux Mar 4 '12 at 18:27
1  
@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 4 '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 tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html and linuxcommand.org –  bodhi.zazen Mar 4 '12 at 18:33
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.