使用 MSYS2,如果我运行msys2_shell.bat
,会mintty
打开一个 bash 登录 shell,但 ~/.profile
不会获取源。
无论如何,如果我在 /bin/bash --login
里面跑mintty
,请~/.profile
获得资源。为什么?
如果我path\to\msys64\bin\bash.exe --login
通过 Windows 提示符而不是msys2_shell.bat
.
PS:我也试过了.bash_profile
。
使用 MSYS2,如果我运行msys2_shell.bat
,会mintty
打开一个 bash 登录 shell,但 ~/.profile
不会获取源。
无论如何,如果我在 /bin/bash --login
里面跑mintty
,请~/.profile
获得资源。为什么?
如果我path\to\msys64\bin\bash.exe --login
通过 Windows 提示符而不是msys2_shell.bat
.
PS:我也试过了.bash_profile
。
禁用(重命名)系统范围/etc/profile
,~/.profile
来源。
经过调查/etc/profile
,我看到了,保留它但评论功能profile_d ()
~/.profile
是来源。此函数在/etc/profile.d/
.
单独禁用它们我意识到罪魁祸首是/etc/profile.d/bash_completion.sh
.
上面写着:
# Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION_COMPAT_DIR" ] && return
# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 4 ] || [ $bmajor -eq 4 -a $bminor -ge 1 ]; then
[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
# Source completion code.
. /usr/share/bash-completion/bash_completion
fi
fi
unset bash bmajor bminor
第一行解释了为什么在运行子shell(第二次)时一切正常:环境变量已经设置,所以脚本返回。
问题是bash_completion.sh
runs /usr/share/bash-completion/bash_completion
,这个问题真的很大,很难把握。
I was having the same issue.
I figured it out with the help of Dan in this ticket's comment thread: https://sourceforge.net/p/msys2/tickets/97
The solution is to edit the /etc/fstab
$ cat /etc/fstab
# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table
# DO NOT REMOVE NEXT LINE. It remove cygdrive prefix from path
none / cygdrive binary,posix=0,noacl,user 0 0
d:/Users/dparker /home/dparker ntfs binary,posix=0,user 0 0
Notice the last line is necessary to mount your home dir... I am not sure why you need to explicitly do this in /etc/fstab
because it seems to mount it without it being there... but maybe it wasn't mounting it properly?
Hope this works for you like it did for me.