Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#4388 - Source /etc/profile

Attached to Project: Arch Linux
Opened by GCN (gilcn) - Thursday, 06 April 2006, 21:23 GMT
Last edited by Judd Vinet (judd) - Wednesday, 12 April 2006, 18:38 GMT
Task Type Feature Request
Category System
Status Closed
Assigned To No-one
Architecture not specified
Severity Very Low
Priority Normal
Reported Version 0.7.1 Noodle
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Is there any reason why /etc/profile isn't sourced after having created a new account ?

One good thing would be to include something like this in the /etc/skel/.bashrc file :
if [ -f /etc/profile ]; then
. /etc/profile
fi

This way, it'll also source home-made scripts putted in /etc/profile.d/
This task depends upon

Closed by  Aaron Griffin (phrakture)
Thursday, 25 May 2006, 16:09 GMT
Reason for closing:  Not a bug
Additional comments about closing:  See last comment - misunderstanding of how loginShells work
Comment by Jan de Groot (JGC) - Thursday, 06 April 2006, 22:01 GMT
bash sources /etc/profile by default AFAIK. I wouldn't know how it reads out my /etc/profile.d/*.sh scripts otherwise.
Comment by Judd Vinet (judd) - Thursday, 06 April 2006, 22:47 GMT
Yes, bash already sources /etc/profile each time it is run. That's what sets your PS1 prompt and all that stuff.
Comment by Judd Vinet (judd) - Wednesday, 12 April 2006, 18:38 GMT
Re-opened by Gilles CHAUVIN:

Since I cannot post comments anymore I use the "request re-open". I just wanted to tell that I have to source /etc/profile on my ~/.bashrc. If I don't do that and I open a Konsole/Xterm/whatever, the /etc/profile* scripts aren't read. Maybe a KDE problem or something else then !
Comment by Judd Vinet (judd) - Wednesday, 12 April 2006, 18:41 GMT
Hmmm, not sure. From the bash(1) manpage:

When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
Comment by GCN (gilcn) - Wednesday, 12 April 2006, 19:20 GMT
The first time I add this problem, I didn't understand why this happened. I then checked on a RHEL4 box to see how it works.

The different files look as follow (I just past the interesting parts):
~/.bash_profile:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

~/.bashrc:
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi


Looking at the end of /etc/bashrc gives:
if ! shopt -q login_shell ; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
. $i
fi
done
unset i
fi

The /etc/profile file contains (at the end):
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

My Arch's ~/.bashrc contains:
# Source global definitions
if [ -f /etc/profile ]; then
. /etc/profile
fi

And since I added those few lines, my /etc/profile.d/* scripts are correctly sourced (proxy settings, color bash prompt, aliases, etc...).
Comment by Jan de Groot (JGC) - Wednesday, 12 April 2006, 20:10 GMT
When you put this in .bashrc, you will end up with a very long PATH, PKG_CONFIG_PATH, etc. bash will re-read the profile.d files on every shell execution, which is not what you want. The files in /etc/profile.d are sourced from your login shell, which is the way we support in archlinux.
Comment by GCN (gilcn) - Wednesday, 12 April 2006, 20:48 GMT
I don't really know what is happening. The fact is, when I logon to my system on, say, vc/1, the files in /etc/profile.d are correctly sourced. When I'm under X and I open a: Konsole, xterm, whatever... Thoses files aren't sourced anymore.

Maybe I'm doing something wrong, maybe there's a bug somewhere...
Comment by Jan de Groot (JGC) - Wednesday, 12 April 2006, 20:53 GMT
The point is, that once these files are sourced, you don't source them after that anymore. Your konsole or xterm or whatever takes the variables from the shell you used to login. These variables are the same ones KDE, GNOME, XFCE, whatever use to build your panel or path.
Comment by Aaron Griffin (phrakture) - Thursday, 25 May 2006, 16:08 GMT
There is a misunderstanding of the way login shells work here. By default, X terminals do not run as login shells. This needs to be configured for any terminal you user.

Take, for instance, xterm:
-ls This option indicates that the shell that is started in the xterm window will be a
login shell (i.e., the first character of argv[0] will be a dash, indicating to
the shell that it should read the user's .login or .profile).

Passing "-ls" forces xterm to be a login shell, and will then run bash as "-bash" (part of the definition of a login shell is that the first char is a dash).

This can be done with Xresources and many many other settings.

The operative point is that no *profile* scripts are sourced if the shell is not a login shell. Start xterm with -ls (or xterm*loginShell: true in ~/.Xdefaults or some other setting) and your files will be sourced as expected.

Closing.

Loading...