Created attachment 465118 [details, diff] /etc/profile.patch Currently, /etc/profiles sources or sets: - /etc/profile.env - other defaults - /etc/bash/bashrc - /etc/profile.d/*.sh I know it's a compromise to source /etc/bash/bashrc in /etc/profile and the comment in /etc/profile documents that too. However, since it's a compromise, sourcing /etc/bash/bashrc should be done completely at the end which is after sourcing /etc/profile.d/*.sh, so: - /etc/profile.env - other defaults - /etc/profile.d/*.sh - /etc/bash/bashrc In most cases it won't make a difference, but in some cases it will. This should be corrected. Patch included.
Correction: Currently, /etc/profiles sources or sets: Should be: Currently, /etc/profile sources or sets:
I don't think I agree with this, /etc/bash/bashrc sets the defaults, then /etc/profile.d/*.sh overrides those defaults with specific settings. Having it sourced in the current order allows one to drop a file in /etc/profile.d to override defaults without having to modify the standard bashrc file.
Please read the man page: roughly said: profile is for environment settings etc bashrc is for aliases / shell specific stuff The only reason /etc/bash/bashrc is called from /etc/profile is because if its not in ~/.profile, it won't be sourced at login. It is a compromise to call it anyway so if it needs to be called from /etc/profile, it should be done completely at the end. Modifying the standard bashrc should be done in ~/.bashrc or /etc/bash/bashrc.d/* anyway profile and bashrc should not be mixed! Note non-login shells do not even source profile, only bashrc so ... Override settings is not applicable & not relevant here ...
Let me give you some hard evidence why /etc/profile.d/*.sh should be sourced before /etc/bash/bashrc. Example: # cat > /etc/env.d/02locale <<'EOF' LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_COLLATE=C LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8 LC_ALL="" EOF # env-update >>> Regenerating /etc/ld.so.cache... # cat > /etc/profile.d/locale_users.sh <<'EOF' [ $(id -u) -ge 1000 ] && export LC_MESSAGES="nl_NL.UTF-8" EOF # cat > /etc/bash/bashrc.d/test_locale.sh <<'EOF' cat /tmp/no_file # does not exist EOF # exit # switch back to regular user $ bash --login cat: /tmp/no_file: No such file or directory $ bash --login cat: /tmp/no_file: No such file or directory $ bash cat: /tmp/no_file: Bestand of map bestaat niet $ bash cat: /tmp/no_file: Bestand of map bestaat niet $ bash --login cat: /tmp/no_file: No such file or directory So clearly, /etc/bash/bashrc acts diffently depending on login-shell or not because /etc/profile hasn't finished doing all of its settings when /etc/bash/bashrc is called too early. However, if (in /etc/profile) you source /etc/profile.d/*.sh before /etc/bash/bashrc, the environment gets consistent for both login-shells and non-login shells: $ bash --login cat: /tmp/no_file: Bestand of map bestaat niet $ bash --login cat: /tmp/no_file: Bestand of map bestaat niet $ bash cat: /tmp/no_file: Bestand of map bestaat niet $ bash cat: /tmp/no_file: Bestand of map bestaat niet So, consistent behaviour is the reason for calling /etc/bash/bashrc after al the profile stuff. Thank you.
ping, any questions?
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/proj/baselayout.git/commit/?id=3d46659bf88caf23cfb631671dbece20bfdf8572 commit 3d46659bf88caf23cfb631671dbece20bfdf8572 Author: William Hubbs <williamh@gentoo.org> AuthorDate: 2017-10-03 21:58:35 +0000 Commit: William Hubbs <williamh@gentoo.org> CommitDate: 2017-10-03 22:01:40 +0000 process files in /etc/profile.d before /etc/bash/bashrc for consistency Bug: https://bugs.gentoo.org/show_bug.cgi?id=610898 etc/profile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)}
This will be in baselayout-2.5.