I noticed redundant entries in my $PATH…
My .bashrc is sourced twice for non-login interactive shells. (once for login shells). Is it an openSUSE decision?
I noticed redundant entries in my $PATH…
My .bashrc is sourced twice for non-login interactive shells. (once for login shells). Is it an openSUSE decision?
Possibly, you are confused by what you are seeing.
Your desktop session startup uses your login shell (presumably bash), and any environment variables set there become available to your entire desktop, including any terminal applications that run a shell. For bash, that includes what is done in “.bashrc”.
When you start a bash shell, as in a terminal application, that again uses “.bashrc”. If you don’t want that, you can instead use a “.profile” in place of a “.bashrc”.
This is very normal unix and linux behavior. It is not limited to openSUSE. For example, I saw similar behavior with Solaris, though I was using “csh” and “.cshrc” in place of “bash” and “.bashrc”.
It is a common practice to avoid redundant PATH entries by testing the current $PATH before you decide to change anything. Or test some other environment variable that you set as a flag to indicate that you have ALREADY_BEEN_HERE .
Hi,
Welcome to the forum. Like what said by nickert the PATH should be in
"$HOME/.profile"
because every time you open a terminal which is a login shell that PATH will multiply/extend/expand or whatever you want to call it.
You can still use ~/.bashrc but you need to do some test, yes test the value of $PATH and not just add an entry to it.
Create a ~/script directory
mkdir -p "$HOME/scripts"
Now put something like this in your ~/.bashrc and save it.
if :$PATH: != *:$HOME/scripts:* ]]; then
PATH=$HOME/scripts:$PATH
fi
You will have a ~/script directory in your “$HOME” and it will be in your PATH, and it will not duplicate the value of PATH regardless how many login shells you have open.
this can be done in ~/.profile as well. Also there is no decision making done by openSUSE or whoever. That behavior of login/non-login shells remains the same. The decision is still yours…
Ok thanks. Many years of Linux and I never noticed that till now!
Which is SUSE specific and rather questionable. .bashrc is expected to be sourced by interactive shell and desktop session startup script is not an interactive shell by any measure. .bashrc is sourced from within /etc/profile and I do not see this being done in e.g. Ubuntu. I would argue that sourcing of .bashrc (and /etc/bash.bashrc) in /etc/profile must at least be protected by check whether shell is interactive.
P.S. OK, Ubuntu actually is sourcing ~/.bashrc from within default ~/.profile, but it guards against non-interactive shell both in /etc/bash.bashrc and default ~/.bashrc.
??
/etc/profile applies variables to the system, without respect to interactive or non-interactive and regardless of shell.
I could be wrong but my assumption has always been that the User path as implemented by default applies only to the Bash shell, typically interactively.
I agree though that although in the SysVinit days the desktop session might have been started by script, today that is not necessarily the case
TSU