#10 Avoid duplicating user path entries
Closed 8 months ago by svashisht. Opened 9 months ago by svashisht.
rpms/ svashisht/bash rhbz1652639  into  master

file modified
+5 -1

@@ -7,7 +7,7 @@ 

  Version: %{baseversion}%{patchleveltag}

  Name: bash

  Summary: The GNU Bourne Again shell

- Release: 5%{?dist}

+ Release: 6%{?dist}

  License: GPLv3+

  Url: https://www.gnu.org/software/bash

  Source0: https://ftp.gnu.org/gnu/bash/bash-%{baseversion}.tar.gz

@@ -320,6 +320,10 @@ 

  %{_libdir}/pkgconfig/%{name}.pc

  

  %changelog

+ * Thu Jan 10 2019 Siteshwar Vashisht <svashisht@redhat.com> - 4.4.23-6

+ - Avoid duplicating user path entries

+   Resolves: #1652639

+ 

  * Mon Oct 08 2018 Siteshwar Vashisht <svashisht@redhat.com> - 4.4.23-5

  - Fix some issues identified by coverity

  

file modified
+4 -1

@@ -6,7 +6,10 @@ 

  fi

  

  # User specific environment

- PATH="$HOME/.local/bin:$HOME/bin:$PATH"

+ if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]

+ then

+     PATH="$HOME/.local/bin:$HOME/bin:$PATH"

+ fi

  export PATH

  

  # Uncomment the following line if you don't like systemctl's auto-paging feature:

Functionally looks correct to me. But please use the multiline format for the if statement to keep the coding style of dot-bashrc consistent.

rebased onto e3b3cd9

9 months ago

This change has been merged manually.

Pull-Request has been closed by svashisht

8 months ago

As I commented on https://bugzilla.redhat.com/show_bug.cgi?id=1615131
I don't like the recent changes to .bashrc and .bash_profile.

But, here's an improvement to this pull request:

if [[ :$PATH: != *:$HOME/.local/bin:$HOME/bin:* ]]; then
  ...
fi

No regular expression involved.

Or, better, make use of the existing pathmunge function (that's been in /etc/profile for many years) to add components to the path. It checks that the component isn't already present:

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}
pathmunge $HOME/.local/bin after
pathmunge $HOME/bin after
unset -f pathmunge

@robin217 Could you please file it as a separate pull request, together with some real-world examples that would be handled better after applying the proposed change?