1
When opening a new terminal, I need to do source ~/.bashrc
or source ~./bash_profile
before my $PATH
variable is initalised. I thought .bashrc
did this automatically? How do I make it so I don't need to do that.
1
When opening a new terminal, I need to do source ~/.bashrc
or source ~./bash_profile
before my $PATH
variable is initalised. I thought .bashrc
did this automatically? How do I make it so I don't need to do that.
2
I'm not sure if I understand your questions but:
Your bash init files should be sourced at boot. If not your system is badly configured or broken.
You didn't mention your Operating System, but I'm guessing you are using Linux, any way.
The sequence of initialization, according to man bash
is the following:
When bash is invoked as an interactive login shell, or as a non-inter‐ active shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.
In an Ubuntu distribution, for example, after loading the /etc/profile
, it looks for a ~/.profile
file that looks like this:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Which means that, if using bash and the file ~/.bashrc
exists it will be loaded/sourced and after that it will set your $PATH variable.
So I suggest you first take a look at your ~/.profile
file and fix it, if necessary.