LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Unexpected directory in path, cannot find source (https://www.linuxquestions.org/questions/linux-general-1/unexpected-directory-in-path-cannot-find-source-712765/)

alanhr 03-19-2009 05:11 AM

Unexpected directory in path, cannot find source
 
Hello all,

I have a problem with a directory in my PATH that should not be there. I have checked /etc/bashrc, /etc/profile, ~/.bashrc, ~/.bash_profile, and the two files that get sourced in by ~/.bashrc and cannot find the unwanted directory anywhere. Based on the order the directories are listed in my PATH, I think it is being inserted after /etc/bashrc and /etc/profile are called, but before ~/.bashrc and ~/.bash_profile are called. However, I cannot figure out how. Any ideas?

I realize I am probably missing something obvious, but at the moment I'm just spinning my wheels -- time to ask for help!

Oh, and in case it makes a difference: 64-bit RHEL 4.7 with bash shell (obviously).

Thanks,

Alan

Agrouf 03-19-2009 06:02 AM

I don't know what is happening since I don't have access to your profile files, but anyway if you want a quick and dirty solution, just add that command in your ~/.bashrc:
export PATH=$(echo $PATH|sed 's/:badpath://g')

Valery Reznic 03-20-2009 12:59 AM

Quote:

Originally Posted by alanhr (Post 3480482)
Hello all,

I have a problem with a directory in my PATH that should not be there. I have checked /etc/bashrc, /etc/profile, ~/.bashrc, ~/.bash_profile, and the two files that get sourced in by ~/.bashrc and cannot find the unwanted directory anywhere. Based on the order the directories are listed in my PATH, I think it is being inserted after /etc/bashrc and /etc/profile are called, but before ~/.bashrc and ~/.bash_profile are called. However, I cannot figure out how. Any ideas?

I realize I am probably missing something obvious, but at the moment I'm just spinning my wheels -- time to ask for help!

Oh, and in case it makes a difference: 64-bit RHEL 4.7 with bash shell (obviously).

Thanks,

Alan

/etc/profile sourced files from /etc/profile.d/ directory.
Culprit can be here

alanhr 03-20-2009 05:39 AM

Quote:

Originally Posted by Valery Reznic (Post 3481643)
/etc/profile sourced files from /etc/profile.d/ directory.
Culprit can be here

Thanks, I checked there but no luck.

I stopped sourcing the external files in my ~/.bashrc and now my PATH looks as it should. I still don't know where a couple of the entries (the ones that were duplicated before) are coming from.

Quote:

Originally Posted by Agrouf (Post 3480530)
I don't know what is happening since I don't have access to your profile files,

Everything is very nearly just the RHEL defaults:

Code:

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
          if [ "$2" = "after" ] ; then
              PATH=$PATH:$1
          else
              PATH=$1:$PATH
          fi
        fi
}

# Path manipulation
if [ `id -u` = 0 ]; then
        pathmunge /sbin
        pathmunge /usr/sbin
        pathmunge /usr/local/sbin
fi

pathmunge /usr/X11R6/bin after


# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
            . $i
    fi
done

unset i
unset pathmunge

Code:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

Code:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
        umask 002
else
        umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
        for i in /etc/profile.d/*.sh; do
            if [ -r "$i" ]; then
                . $i
            fi
        done
        unset i
fi
# vim:ts=4:sw=4

Code:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Set up Pango for 64-bit environment by default.
#
export PANGO_RC_FILE=/etc/pango/pangorc64

As I said, I quit sourcing any external files. All they did, though, was append stuff onto the PATH.

Thanks for the advice,

Alan


All times are GMT -5. The time now is 07:28 PM.