The .bashrc
file is designed to hold things you want executed each time a new interactive shell is started. This isn't the right place to set your PATH
variable, for example, you should only have things that you need to run on each shell initialization.
This is why we have two "families" of configuration files for bash:
/etc/bashrc
, ~/.bashrc
are read each time a new interactive shell that is not a login shell is started.
/etc/profile
, ~/.bash_profile
, ~/.bash_login
, and ~/.profile
(in that order) are sourced each time a new interactive login shell is started.
What this means in practice, for most systems, is that the ~/.profile
group of files are read once, when you log in and then the ~/.bashrc
files are read each time you open a new terminal or start a new interactive shell.
Therefore, if you see that things in your ~/.bashrc
are being executed and causing you problems each time you start a new shell, that means your system has been misconfigured and you're using ~/.bashrc
when you should be using ~/.bash_profile
or ~/.profile
. In other words, yes, .bashrc
is absolutely supposed to be executed every time you start a new interactive non-login shell.
.bashrc
is that it is read each time you start a new interactive shell.exec bash
starts such a shell (although justbash
is usually what you want). How else would it work? – terdon Sep 15 '20 at 12:52bashrc
should detect if you are doing a shell reload and avoid doing things twice. – ivan_pozdeev Sep 15 '20 at 12:54~/.bashrc
that belong in~/.profile
instead? See Is there a ".bashrc" equivalent file read by all shells? and the links therein. – terdon Sep 15 '20 at 12:56PATH
manipulation, entries may now be in a wrong order. – ivan_pozdeev Sep 15 '20 at 18:31.bashrc
. Read the answer I linked to above, PATH settings belong in.profile
..bashrc
should only have things you want to run on each new shell you open. – terdon Sep 16 '20 at 08:01