Cygwin shell不执行.bashrc

Eva*_* Y. 12 shell cygwin

启动cygwin shell后,它只是位于错误的主目录中:

xfire@codingme.com ~
$ pwd
/cygdrive/c/Users/xfire
Run Code Online (Sandbox Code Playgroud)

但它曾经是/ home/xfire

xfire@codingme.com /etc
$ cat passwd | grep xfire
xfire:unused:22773:10513:U-CORP\xfire,S-1-5-21-527237240-725345543-682003330-12773:/home/xfire:/bin/bash
Run Code Online (Sandbox Code Playgroud)

并且/ home/xfire中的.bashrc没有被执行,即使我将它复制到/ cygdrive/c/Users/xfire,它也不起作用!

gle*_*man 34

在cygwin上,我将此添加到我的~/.bash_profile:

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

  • 这解决了我.也许你可以澄清一下发生了什么,以及为什么Evans Y.想要接受他的答案? (3认同)
  • 对于其他人可能会好奇为什么。cygwin 默认终端程序是 mintty。如果您检查用于启动终端的图标的属性,您会发现它以一个单独的“-”结尾。这告诉 mintty 将 shell 作为登录 shell 运行。如果 shell 是 **not** 登录 shell,那么 Bash 只会执行 .bashrc 。对于登录 shell,它只执行 .bash_profile(或 .profile)。在许多其他 unix 中,终端程序将 shell 作为非登录 shell 启动,因此它们默认执行 .bashrc 而不是 .bash_profile。 (2认同)

Eva*_* Y. 10

某些程序在Windows注册表中添加"HOME"环境并将值设置为"C:\ Users\xfire",这就是为什么cygwin将该目录作为主目录.cygwin.com/faq-nochunks.html


Jam*_*son 5

在我的cygwin版本中,我发现只有~/.profile被执行了,所以添加了

if [ -e "${HOME}/.bash_profile" ]; then
    source "${HOME}/.bash_profile"
fi
Run Code Online (Sandbox Code Playgroud)

.profile文件。我的.bash_profile文件包含另一个测试,.bashrc并从那里执行。我还在文件中添加了以下两行.bashrc

export BASH_ENV="${HOME}/.profile"
export ENV="${HOME}/.profile"
Run Code Online (Sandbox Code Playgroud)

这些中的第一个确保可.profile在非交互式终端中执行,第二个确保可在POSIX终端中执行。在Bash参考手册中,我找到了关于运行什么以及何时运行的非常有用的解释。

对于您而言,这无济于事,因为您的HOME环境变量的值存在问题,但是在搜索此问题时,此页面在列表中的位置很高。