Greg Wooledge wrote:
> On Tue, Aug 20, 2019 at 02:27:40PM +0000, Vipul wrote:
>> Hi there,
>>
>> From few days, I'm trying find answer of a question "which program does
>> read ~/.profile if I login from graphical user interface (for ex: GNOME)?".
> 
> https://wiki.debian.org/Xsession
> https://wiki.debian.org/EnvironmentVariables
> 
> These are, of course, incomplete.
> 
> The short answer is: if you login through a Display Manager (a graphical
> login program), NOTHING reads ~/.profile.  Ever.
> 

Try this if you're using GNOME with bash as a default shell. Export two
variables in $TEST_PRO and $TEST_BASH by adding these line `export
TEST_PRO="Hello from profile"` and `export TEST_BASH="Hello from bash"`
in ~/.profile and ~/.bash_profile file respectively.

Now, login from GNOME interface and run following command in gnome-terminal

$ echo "$TEST_PRO"
Hello from profile

$ echo "$TEST_BASH"

(output is empty string that means TEST_BASH variable is unset. see
below output of hd command)

$ hd <<< "$TEST_BASH"
00000000  0a                                                |.|
00000001

Whereas, login from console then behavior is reversed

$ echo "$TEST_PRO"

(output is empty string. see below output of hd command)

$ hd <<< "$TEST_PRO"
00000000  0a                                                |.|
00000001

$ echo "$TEST_BASH"
Hello from bash

which is kind of expected behavior because is presence of
~/.bash_profile file login shell (bash) will not read ~/.profile but,
not clear who reads ~/.profile when login from GNOME interface.
    I think, it's sh (bourne) shell because according to INVOCATION
section bash man page if bash is invoked as sh, it tries to mimic bash
behavior by reading ~/.profile.

This behavior have something to do with Debian default configuration not
with any part of graphical interface program.

> So, let's try to guess what the actual goal is here.
> 
> If your goal is to set an environment variable in every program in your X
> session, and you're not using GNOME, then you can put an export command
> in ~/.xsessionrc and it should work great.
> 
> If you are using GNOME, please find out how to do it, and then tell us,
> because as far as I've been able to determine, GNOME makes this completely
> impossible.
> 

I asked this on #gnome:gnome.org they said try ~/.config/environment.d/

> Normal window managers run programs as children of themselves, using the
> standard Unix fork-and-exec model.  The window manager is executed with
> various environment variables, umask, resource limits, and so on, and
> its children inherit these.  So, the standard Unix login configuration
> stuff all works.  You edit a magic dot file, you login, the dot file is
> read by a shell, the shell executes your window manager, the WM inherits
> your desired environment, and everything launched from the WM also
> inherits this environment.  Easy peasy.
> 
> But with GNOME, applications are launched by sending a message to dbus,
> and then dbus spawns things as *its* children.  They are not children of
> the WM.  They do not inherit the environment from the WM.  They inherit
> the environment from dbus.
> 
> And there is no known way to configure the environment of dbus in a way
> that is useful to end users.
> 

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to