MSYS2 does not source .profile

3.5k Views Asked by At

Using MSYS2, if I run msys2_shell.bat, mintty opens a bash login shell, but ~/.profile does not get sourced.

Anyway if I run /bin/bash --login inside mintty, ~/.profile get sourced. Why?

The same happens if I run path\to\msys64\bin\bash.exe --login via Windows prompt instead of msys2_shell.bat.

PS: I tried also with .bash_profile.

2

There are 2 best solutions below

0
On

Disabling (renaming) system wide /etc/profile, ~/.profile is sourced.

After investigating /etc/profile I saw that, keeping it but commenting the function profile_d () ~/.profile is sourced. This function runs the scripts in /etc/profile.d/.

Disabling them individually I realized that the culprit is /etc/profile.d/bash_completion.sh.

It reads:

# 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

The first line explains why when running the subshell (the second time) things work: environment variables are already set, so the script returns.

The problem is that bash_completion.sh runs /usr/share/bash-completion/bash_completion, which is really huge and it is difficult to grasp the problem.

1
On

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.