Possible issue in /etc/bashrc?

Hi all,

I noticed that the part of /etc/bashrc that controls the PATH is doubled sourced event though the file attempts to prevent the double sourcing by checking if the BASHRCSOURCED environment variable is set. if not it sets it but does not export it. The check is therefiore useless and there’s no protection against multiple sourcing it.

The impact is that the PATH grows inside each Bash sub-shell.

The fix is simple, but the location of the check must move, otherwise interactive sub-shells won’t use the same prompt.

My questions:

  1. Where is the Git repository where the source of the /etc/bashrc is located? It’s probably upstream, right?
  2. Where would I find information to report this problem and propose a fix?

For reference, here’s the diff between the original /etc/bashrc on Rocky Linux 8.10 and a version I modified:

--- bashrc	2024-12-04 11:51:35
+++ new-bashrc	2024-12-04 11:52:05
@@ -8,32 +8,29 @@
 # /etc/profile.d/ to make custom changes to your environment, as this
 # will prevent the need for merging in future updates.
 
-# Prevent doublesourcing
-if [ -z "$BASHRCSOURCED" ]; then
-  BASHRCSOURCED="Y"
 
-  # are we an interactive shell?
-  if [ "$PS1" ]; then
+# are we an interactive shell?
+if [ "$PS1" ]; then
     if [ -z "$PROMPT_COMMAND" ]; then
-      case $TERM in
-      xterm*|vte*)
-        if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
-            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
-        else
-            PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
-        fi
-        ;;
-      screen*)
-        if [ -e /etc/sysconfig/bash-prompt-screen ]; then
-            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
-        else
-            PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
-        fi
-        ;;
-      *)
-        [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
-        ;;
-      esac
+        case $TERM in
+            xterm*|vte*)
+                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
+                    PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
+                else
+                    PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
+                fi
+                ;;
+            screen*)
+                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
+                    PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
+                else
+                    PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
+                fi
+                ;;
+            *)
+                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
+                ;;
+        esac
     fi
     # Turn on parallel history
     shopt -s histappend
@@ -48,8 +45,13 @@
     #   PS1="[\u@\h:\l \W]\\$ "
     # fi
     # to your custom modification shell script in /etc/profile.d/ directory
-  fi
+fi
 
+# Prevent doublesourcing
+if [ -z "$BASHRCSOURCED" ]; then
+  BASHRCSOURCED="Y"
+  export BASHRCSOURCED
+
   if ! shopt -q login_shell ; then # We're not a login shell
     # Need to redefine pathmunge, it gets undefined at the end of /etc/profile
     pathmunge () {

I did a little more digging, from Rocky Linux 8.4:

  • rpm -qf /etc/bashrc identifies the package that provides /etc/bashrc: setup-2.12.2-11.el8.noarch
  • rpm -qi setup provides a stale URL (https://pagure.io/setup/) that has been replaced by https://src.fedoraproject.org/rpms/setup

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.