LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to remove a path from the default $PATH (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-a-path-from-the-default-%24path-917809/)

ztdep 12-08-2011 07:00 PM

how to remove a path from the default $PATH
 
Dear friends:
My system $PATH is :
/usr/lib64/mpi/gcc/openmpi/bin:/home/ztdep/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit

i want to delete the first "/usr/lib64/mpi/gcc/openmpi/bin" , since i need to install the mpich2.2 by myself
Could you please give me some help.

Tinkster 12-08-2011 07:47 PM

Depends on how it got added ...
  1. System global
    • /etc/profile
    • /etc/profile.d/*
  2. User specific
    • ~/.bashrc
    • ~/.bash_login
    • ~/.bash_profile
    • ~/.profile

Check the files/directories ... if it under /etc/profile.d/ just grep for the path.


Cheers,
Tink

David the H. 12-08-2011 11:59 PM

As Tinkster says, if you want to change it permanently, you need to track down the line where it's being set, and modify that.

But to remove an entry from the current PATH "on the fly", you can use a simple parameter substitution.

Code:

del='/usr/lib64/mpi/gcc/openmpi/bin:'
export PATH="${PATH//$del}"

Just take care to note which side the colon needs to be on, if the pattern is at the beginning or end of the path.

I use this technique in a small function that toggles the availability of a directory of scripts I only need to use occasionally (I don't like to have them generally available, as they clutter up some common tab completions).

Code:

myscripts (){
    local pathadd="$HOME/myscripts"

    if [[ $PATH =~ $pathadd ]]; then
        export PATH="${PATH//:$pathadd}"
        echo "myscripts off"
    else
        export PATH="$PATH:$pathadd"
        echo "myscripts on"
    fi
}


ztdep 12-10-2011 11:52 PM

Quote:

Originally Posted by Tinkster (Post 4545574)
Depends on how it got added ...
  1. System global
    • /etc/profile
    • /etc/profile.d/*
  2. User specific
    • ~/.bashrc
    • ~/.bash_login
    • ~/.bash_profile
    • ~/.profile

Check the files/directories ... if it under /etc/profile.d/ just grep for the path.


Cheers,
Tink

Dear tink:
Thank you very much for your feedback. The path is the default PATH after i installed the opensuse 12.1.
I have use the grep in the "/etc/profile /etc/profile.d/* and /.bashrc /.profile , it can not find anything.
Could you please give me futher instruction.
Regards

catkin 12-11-2011 12:02 AM

Code:

grep PATH /etc/profile /etc/profile.d/* ~/.bashrc ~/.bash_login ~/.bash_profile ~/.profile

Tinkster 12-11-2011 12:03 AM

Quote:

Originally Posted by ztdep (Post 4546945)
Dear tink:
Thank you very much for your feedback. The path is the default PATH after i installed the opensuse 12.1.
I have use the grep in the "/etc/profile /etc/profile.d/* and /.bashrc /.profile , it can not find anything.
Could you please give me futher instruction.
Regards

How odd ... You could try the following

Code:

find /etc -type f -exec grep -H /usr/lib64/mpi/gcc/openmpi/bin {} \;

Cheers,
Tink


All times are GMT -5. The time now is 04:09 PM.