blob: 8d418d28723157396721693373bfa4780575c624 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
I've long been confused as to whether I should put environment variable in my ~/.bash_profile or ~/.bashrc file. As it turns out I'm not the only one who can't keep these straight. Luckily for you and I, a blogger by the name of Josh Staiger is not so lazy he can't be bothered to type man bash.
Staiger's post is almost two years old and I don't remember how I stumbled across it, but as with most things *nix there haven't been any major changes lately.
Here's Staiger's explanation of the difference between the two files:
>According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
>What I take this to mean is that when I login when using a console, either physically at the machine or using ssh, .bash_profile is executed.
>However, if I launch a terminal within a windowing system such as KDE, launch the Emacs *shell* mode, or execute /bin/bash from within another terminal then .bashrc is executed.
If keeping the two straight is just too much effort, Staiger points out that most people tend edit the files so one calls the other. That way you can keep all your variables in one place without having to keep track of which file is used by which shell type. To enact this sort of trickery you'll need to open .bash_profile and uncomment the following lines:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
Those lines may not be there on some flavors of *nix, for instance they we're there on my OS X machine, but adding them in seems to work. Let me know if you have problems.
|