Weird anomaly in Fedora 35: ZSH | username/bin directory is in PATH twice?

,

Greetings,
I am coming back to Fedora after a couple of years away and was previously using PopOs (System 76). I wanted to come to Fedora because of Gnome 41 vs 40 and ran into a weird occurrence when configuring my CLI, specifically, the PATH environment variable. It is listing my /home/username/bin directory two times and I am trying to correct the Path so it works correctly. Is it seeing the directory in more than one place where the $PATH env variable is spawned?

Here is the output from echo $PATH:
/opt/Simplenote/:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/user/bin:/home/user/bin:/usr/local/go/bin. My username has been altered to ‘user’ for privacy reasons.

My Kernel Version is:
Linux phenom-ii 5.15.11-200.fc35.x86_64 #1 SMP Wed Dec 22 15:41:11 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Hope someone can shed some light on where I can correct this, or is it not something to be concerned about?

Thanks in Advance!

1 Like

Quick answer: this doesn’t seem to be the default config, but it’s harmless. We can investigate further, though:

Details:

I just created a clean testuser on my system to see, and the resulting PATH looks like this:

$ echo $PATH | tr : '\n'
/home/testuser/.local/bin
/home/testuser/bin
/usr/lib64/qt-3.3/bin
/usr/share/Modules/bin
/usr/lib64/ccache
/usr/local/bin
/usr/bin
/usr/local/sbin
/usr/sbin

… with no duplicates. You may get different results from me, because some of these things are here because of different packages installed on my system. I think the likely things are:

  1. You have some configuration of your own that adds /home/username/bin (maybe expressed as ~/bin) that you’ve been carrying around since before that became part of the defaults. (This is actually the case on my own mattdm account, which is why I created a test user to look into this.)

  2. Or, there is some package that adds it without checking if it’s already there.

Either way, it’s basically harmless — redundant, but the cost of looking twice is very very low.

We can try to figure out what’s going on by looking at the relevant bash configuration. For case 1, look in /etc/profile.d for snippets added by various packages:

$ grep -w PATH /etc/profile.d/*
/etc/profile.d/ccache.sh:case ":${PATH:-}:" in
/etc/profile.d/ccache.sh:    *) PATH="/usr/lib64/ccache${PATH:+:$PATH}" ;;
/etc/profile.d/qt.sh:case :$PATH: in
/etc/profile.d/qt.sh:    *) PATH=$QTDIR/bin:$PATH ;;
/etc/profile.d/qt.sh:export QTDIR QTINC QTLIB PATH

I don’t have the redundant home entries, but you can see from the above where the ccache and qt related ones are coming from. I can further investigate with:

$ rpm -qf /etc/profile.d/ccache.sh /etc/profile.d/qt.sh
ccache-4.2.1-2.fc35.x86_64
qt3-3.3.8b-88.fc35.x86_64

to see what packages those specific files come from.

For the second case, look at the file ~/.bash_profile (or possibly ~/.profile) for PATH-related lines.[1] In my case for my mattdm account, I have

export PATH=$HOME/bin:$PATH:$HOME/.cargo/bin

… which is what causes the redundant entry for me.

PS: people often ask me “How do you become a Linux expert?” And the fundamental answer is: by becoming curious about things like this and looking into them. :classic_smiley:


  1. could also be ~/.bashrc, but that’s technically not the right place for environment variables to be set ↩︎

4 Likes

I agree ~/.bashrc is not the right place for environment variables to be set, including PATH. I hope a future Fedora release will move the default user-specific PATH customization back to ~/.bash_profile, where it was prior to Fedora 30.

1 Like

As indicated by the 2nd paragraph in /etc/bashrc, create file /etc/profile.d/custom.sh. Enter into this file

# /etc/profile.d/custom.sh
printf ‘%s %s\n’ ‘Loading /etc/profile.d/custom.sh’\
‘(See /etc/bashrc or /etc/profile)…’
my_bin=‘’ # Path to $HOME/bin
if my_bin=$(echo $PATH | grep “$HOME/bin”); then
printf ‘%s\n’ “Path to \”${my_bin##*:}\" already set."
else
PATH=$PATH:$HOME/bin
printf ‘%s\n’ “PATH (${PATH##*:} added)”
fi

Add a “if shopt -q login_shell; then … fi” conditional to determine whether
login/non-login shell. As @mattdm indicated, PATH in .bash_profile is probably the redundancy if using a login shell so comment out. Of course, the else part
isn’t necessary if only testing. Do you have the redundancy in non-login shell?
Added:
For those unsure about login/non-login and when bashrc/.bashrc and profile/.bash_profile are invoked, in the following files

  1. /etc/bashrc

  2. /etc/profile

  3. ~/.bashrc

  4. ~/.bash_profile

enter, e.g., printf ‘%s\n’ ‘Loading /etc/FILENAME’. Observe as USER and ROOT
and as login/non-login (using CTL+ALT+F3 as ROOT and CTL+ALT+F4 as USER are automatic
login shells; otherwise, use bash -l).
Make your .bashrc file short. Put, as pointed out above, the ENV variables in the custom.sh.

Thanks guys. I did forget to mention that I am running ZSH not Bash. But if it is not of concern than I will not obsess on it. Just never saw this before and as I may have stated, been a Linux user for over 35 years now. Since at least 1991!

I will look into the suggestions to just see if I can find the app that might be adding to PATH without checking just for learning something more about the system.

Happy New Years and Thanks Again!


J. Mike

(edited - post no email addresses here please)

Add
typeset -U path

To the file you’re setting path in.

~/.zshrc

FYI, 1900809 – /etc/zprofile shouldn't add $HOME/bin to $path

/etc/zprofile is the offending item.

3 Likes

Hi there: I am going to take this advice and add it to my .zshrc. One question, add it as posted or is path uppercase like my export statement—for example ‘export PATH=$PATH’. Thanks!


J. Mike

https://zsh.sourceforge.io/Guide/zshguide02.html#l24

path
In zsh, path is the array that makes up PATH.

1 Like

That actually makes a lot of sense.

Thanks Again


J. Mike

Hi grumpey! Thanks to you for the SOLUTION to the issue!!

It turns out that your post about /etc/zprofile (you copied in the bug report) was the first part of the solution. The second was your other reply to add the typeset to .zshrc. Those together actually solved the problem, so I wanted to post that this was the SOLUTION, so I am marking the issue as SOLVED, Thanks to all who responded! Please note that the soliution was indeed two diffrent replies to my original post.

1 Like

@iainnitro , in your own interest. please don’t post your email here. Thank you! For now, I have removed it from above posts.

Thank you for correcting it. I was not aware that my email was posted with the response. I will be more careful in future.

Thanks!
Michael

I have encountered that issue before when replying to a post from my email which includes my signature & has my email in the sig.