.bash_profile statements get executed twice
Solution 1:
I'm not familiar with how to fix on Windows but if it were UNIX/Linux you could do:
echo $PATH <br />
and see where you're getting your double entry from. I'm speculating that your .bash_profile is being added to the path more than once. If you track down where the path is being manipulated you can fix your problem.
Solution 2:
I had the same problem and noticed there was no ~/.bashrc file.
Creating an empty ~/.bashrc resolved the issue:
touch ~/.bashrc
I could only speculate as to why this worked, but it did.
Solution 3:
TL;DR — try removing --login
from your bash invocation
If you're using Git for Windows with ConEmu or Cmder, the command to start bash probably looks something like this:
cmd /c ""%ConEmuDir%\..\git-for-windows\bin\bash" -i --login"
Note the --login
bit. Apparently, if --login
is passed to bash, it will first execute the commands from /etc/profile
, then execute one of ~/.bash_profile
, ~/.bash_login
, or ~/.profile
— whichever exists.
Now, msys provides an /etc/profile
, which executes all scripts under /etc/profile.d
. Cmder offers /etc/profile.d/cmder.sh
, which executes ~/.bashrc
(excerpt below)
# Source the users .bashrc file if it exists
if [ -f "${HOME}/.bashrc" ] ; then
. "${HOME}/.bashrc"
fi
That's all done within the execution of /etc/profile
. Afterward, bash --login
will try to execute ~/.bash_profile
. Git for Windows generates this ~/.bash_profile
:
# generated by Git for Windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc
Upon execution, ~/.bashrc
gets run a second time.
Solution? Remove --login
from bash's invocation. In Cmder/ConEmu, this can be done by hitting the down-arrow next to the plus button, finding your bash in the list, and changing the command to:
cmd /c ""%ConEmuDir%\..\git-for-windows\bin\bash" -i"
Without the --login
bit, bash will skip executing /etc/profile
, and only run ~/.bashrc
(... and /etc/bash.bashrc
, but msys doesn't execute the ~/.bashrc
there)