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?


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.

  • 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
  • 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 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 – Panther Mar 4 '12 at 18:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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