I believe this is happening because gdm-x-session is sourcing my .profile twice. I added a logging message to my .profile and saw it twice in the journalctl --user output by gdm-x-session. I also found a bug entry from 2002 for a different Linux distro which might be related.
This issue does not present itself when logging in through the Linux virtual console.
Of course a workaround would be to make my .profile idempotent but I’d like to solve the deeper issue.
Yeah that’s one workaround but I don’t think it gives GUI applications access to my local bin. I could also rename .profile to .bash_profile and that works perfectly. However, I would like to figure out why my current setup doesn’t work as expected.
If you look at /etc/profile near the end it has this comment
# Source global bash config, when interactive but not posix or sh mode
if test "$BASH" &&\
test -z "$POSIXLY_CORRECT" &&\
test "${0#-}" != sh &&\
test -r /etc/bashrc
then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bashrc
# Check for double sourcing is done in /etc/bashrc.
. /etc/bashrc
fi
This means that logging in from the virtual console is treated differently than when opening a terminal window.
In both cases the users ~/.bashrc is used and things may be duplicated.
Having an entry duplicated in $PATH is not a serious error but may cause a very minute delay in response to a command that is located after searching the same path twice.
On my $PATH I also see /home/USER/.local/bin:/home/USER/bin twice. Once when added at the beginning of $PATH and once at the very end of $PATH.
Using the gnome terminal I see this in ~/.bashrc
# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH
which adds the users path portion to the very beginning of the $PATH variable. Note that most users prefer this location so that their own commands may be found first without searching the entire $PATH.
then looking at ~/.bash_profile we see
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
which adds the same path to the end of $PATH.
This seems the source of the duplicate entries in ones $PATH variable.
A bad decision was made in Fedora 30 to fix a cockpit bug (1615131 , #12803) by moving PATH customizations from .bash_profile to .bashrc (commit , PR).
.bashrc is supposed to be only for interactive shells. .bash_profileshould source .bashrc only if interactive:
# .bash_profile
# Get the aliases and functions
-if [ -f ~/.bashrc ]; then
- . ~/.bashrc
-fi
+case "$-" in *i*)
+ if [ -f ~/.bashrc ]; then
+ . ~/.bashrc
+ fi;;
+esac
# User specific environment and startup programs
--- a/dot-bash_profile
+++ b/dot-bash_profile
@@ -6,7 +6,3 @@ if [ -f ~/.bashrc ]; then
fi
# User specific environment and startup programs
-
-PATH=$HOME/.local/bin:$HOME/bin:$PATH
-
-export PATH
diff --git a/dot-bashrc b/dot-bashrc
index 1130779..68854a1 100644
--- a/dot-bashrc
+++ b/dot-bashrc
@@ -5,6 +5,10 @@ if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
+# User specific environment
+PATH="$HOME/.local/bin:$HOME/bin:$PATH"
+export PATH
+
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
True, I looked at the .bash_profile on my user and then later realized that is there because of the fact I have upgraded several releases, probably from at least F30, while keeping the data in /home.
The /etc/skel/.bash_profile is different than /home/USER/.bash_profile.
Ok so I finally figured it out. I don’t use any of the Fedora configuration files that are copied over from /etc/skel, I just have my own .bashrc and .profile. What was happening was that gdm-x-session sources .profile and then, either before that or after it launches a default login shell (in my case Bash), which also sources .profile because it can’t find .bash_profile. Seems like a bug in GDM but I’m not sure if it’s reproducible in Wayland so they might not care.