Why GNOME Display Manager always read .profile

gdmgdm3gnomegnome3zsh

I recently switched from terminal prompt login (getty?) to GNOME Display Manager. It seems that GDM always reads .profile, regardless of user's setting of login shell (Zsh in my case). Why is that? I assume it's hardcoded in their source, but I can't find. Why did they do that? Does the software depends on some functionality of Bourne shell?

This is not very good if I want to use both GDM and getty (as fallback), because I then need to keep my .profile and .zprofile in sync. I'm not so confident about sourcing .profile in .zprofile (I met some compatibility issues before, when I tried to source .bashrc in .zshrc). I think Bash called as /bin/sh behaves in POSIX mode, but I'm not sure whether it avoids all the pitfalls.

In case it matters, I'm on latest Arch Linux, running GNOME with Wayland (so there should not be any Xsession script involved).

Best Answer

Your problems with .bashrc are unrelated. .profile needs to be compatible with all sh-compatible shells, whereas of course .bashrc is specific to Bash and should generally not be sourced by other shells.

Generally, put the stuff you want to share between shells in .profile, and make sure you do source it from the startup files of your other shells (unless of course they already do that by default).

Obviously, you need to make sure you avoid code which behaves differently in different shells (lack of quoting is okay in Zsh but a problem in properly Bourne-compatible shells, for example).

As for the "why" part of your question, this is so that settings in your .profile are available to programs you run from your GUI session, not just by the ones you run from within a shell (or maybe we should say "traditional" shell, and regard your GUI session as a "non-traditional" shell).

Related Question