Git for Windows不会执行我的.bashrc文件

Jez*_*Jez 43 windows git bash windows-7

我刚刚在Windows 7上安装了Git for Windows 2.5.0,.bashrc当我运行Git Bash时,我的文件似乎没有被执行.

我创建了这样的文件:

Administrator@HintTech-Dev MINGW64 /
$ pwd
/

Administrator@HintTech-Dev MINGW64 /
$ cd ~

Administrator@HintTech-Dev MINGW64 ~
$ pwd
/c/Users/Administrator

Administrator@HintTech-Dev MINGW64 ~
$ touch .bashrc

Administrator@HintTech-Dev MINGW64 ~
$ vi .bashrc

[... I insert the line "ZZZTESTVAR=234" (without the quotes) into the file in vim ...]

Administrator@HintTech-Dev MINGW64 ~
$ exit
Run Code Online (Sandbox Code Playgroud)

然而,当我下次运行Git Bash时:

Administrator@HintTech-Dev MINGW64 /
$ set | grep ZZZ

Administrator@HintTech-Dev MINGW64 /
$ cat ~/.bashrc
ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$ ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$ set | grep ZZZ
ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$
Run Code Online (Sandbox Code Playgroud)

我为什么不.bashrc跑?它似乎是在正确的地方,并拥有正确的权限.

Jez*_*Jez 70

好的,我发现了问题.很简单,最新的Git for Windows 2.5.0(mintty)使用的bash终端无需阅读.bashrc- 它读取.bash_profile.因此,您可以设置您的环境.bash_profile和/或将此代码放在开头阅读.bashrc:

if [ -f ~/.bashrc ]
then
    . ~/.bashrc
fi
Run Code Online (Sandbox Code Playgroud)

  • 解决方案今天仍然有效 2020 年 5 月 在 Windows 10 git bash 上 (2认同)

小智 19

当我在Windows 10中升级到Git Bash 2.5.0时,我发生了同样的事情.我重命名了我的'.bashrc' - >'.bash_profile'并重新启动了Git Bash.一切都像往常一样正常工作.

mv ~/.bashrc ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)