[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: xsession file



Nguyen, Cuong K. wrote:
> Bob Proulx wrote:
> >  #!/bin/bash --login
> >  exec x-session-manager
> ...
> Follow your instruction, I tried:
> 
> #!/bin/sh

Grr...  That is *NOT* what I instructed there.

> exec gnome-session
> 
> and it works like charm. I still do not understand why I should have 
> --login option there, and why /bin/sh or /bin/bash; also how to know 
> "bash is my login shell". Sorry for stupid questions, but I am too new 
> to this. :(. I used to use windows and just moved to linux in some months.

I base this upon the KDE FAQ entry.  Gnome is similar.  (By the way,
this FAQ moves around periodically.  In the future if you are reading
this in the mail archive you may have to search for it to find the
current location.  It has moved since I last went to look for it.)

  http://docs.kde.org/development/en/kdebase/faq/configure.html#id2560031

  10.7. KDE (kdm) does not read my .bash_profile!
    
  The login managersxdm and kdm do 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.

At login time from a traditional login environment, meaning a console
login, or a serial terminal login or a network login using telnet,
rlogin, rsh, or most importantly today ssh, the shell sources the
user's login environment.  See the bash manual in the INVOCATION
section for more information.  In summary the /etc/profile then the
.bash_profile (or .profile if the .bash_profile does not exist) is
sourced.  In that file is the location where PATH and other variables
are customized.  Usually the ~/.bash_profile sources the ~/.bashrc
file explicitly.

But by default neither KDE nor Gnome are configured to source those
files as stated in the above FAQ entry.  I think that is a mistake and
it has been reported as a bug previously.  I think they simply did not
have a good way to handle it and gave up trying.  Eventually it will
get fixed.

Therefore in order to configure Gnome and KDE to set up a login
environment and to source the users ~/.bash_profile file as a login
environment should do then we do as the FAQ suggested and set up a
~/.xsession file.  In that xsession file load *the same shell* as your
normal command line shell.  I find it implausible to believe that you
are using /bin/sh as your command line shell and therefore it should
not be used in the #! line.  Use your login shell.

By default when a new user account is set up the /bin/bash shell is
set as the user shell.  This may be changed by the user to another
shell.  Other popular shells include zsh, ksh and others.  You can
check your shell by checking the value of the $SHELL variable.

  echo $SHELL

Place that value into the #! line and add *one* option (one is all
that is allowed on #! lines portably) that configures that shell for a
login shell so that it will read the /etc/profile, ~/.bash_profile
files.  For bash that is the --login option.  For ksh it is -l.  I
don't know what it would be for zsh but probably -l too.  Read the man
page for your shell.  Since you keep saying you are a new user I
expect you are using the default bash shell and therefore unless you
have explicitly changed it you are using the bash shell and your line
should say '#!/bin/bash --login'.  (Or '#!/bin/bash -l' is okay too
but --login is much more obvious what it is doing.)

Most people today use a graphical login manager.  This was
traditionally the X Display Manager screen or XDM.  Today this has
been replaced with spiffier fancy versions GDM or KDM.  The GDM and
KDM give users choices to select their session manager.  If you select
Gnome or select KDM then it loads only those session configurations
and will not load your .xsession file!  This is a common trap for
users.  In order to load the .xsession file you must select the
default session.  Default in this case means you control it in your
~/.xsession file.  If you pick Gnome or if you pick KDE then no other
configuration is loaded and your ~/.xsession is ignored.  So head's up
about this potential trap.

Bob



Reply to: