Monday, 1 February 2010

Sourcing .profile

In an earlier post I mentioned that XDM doesn’t source ~/.profile. Here is a collage of stuff that describes and solves the problem.

According to Jason Jesso, the basic problem is mentioned in the KDE FAQ:

9.11. KDE (kdm) does not read my .bash_profile!

Well, xdm (and kdm) does not run a login shell, so .profile, .bash_profile, etc. are not sourced. When the user logs in, xdm runs Xstartup as root and then Xsession as user. So the normal practice is to add statements in Xsession to source the user profile. Please edit your Xsession and .xsession files.

Useful details and a solution are offered by Bill Hassel:

Normally, when you run a script, the shell firks a new copy of the shell which then runs the script. All changes to shell environment are left with this shell. When the script terminates, the forked shell also terminates and nothing is passed back to the current shell except a numeric exit code.

Sourcing causes the current shell to run all the instructions locally, which leaves all the changes in the current environment. Any script can be sourced. The source command is just the character . (dot or period). You put the dot in front of the script with at least one space.

In other words, add

. ~/.profile

to .xsession

Another way is described by James Richard Tyrer

You can also change the first line of “/etc/X11/xdm/Xsession”:

#!/bin/bash -login

I’ll try this on a SD installation soon.