Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a function which is supposed to remove duplicate copies of directories from my PATH environment variable. I have created some duplicates so I can test it but I don't know how to:

1) put the script in the $HOME/.bashrc file

This may seem stupid but I can't figure it out.

share|improve this question
add comment

2 Answers

Just edit the .bashrc file (better make a copy of the original first, just in case) and simply add a line the name of the script you want to execute to the file (at the bottom of the .bashrc would be fine).

If the script is not in your home directory, be sure to specify the complete path.

share|improve this answer
    
i am new to linux i don't know how to edit the bashrc file yet or to do what you said, can you please walk me through the steps –  Johnny Williem Jun 15 '12 at 4:06
    
@JohnnyWilliem You have to be a bit more specific - what part makes no sense? –  Levon Jun 15 '12 at 4:06
    
1)how to i edit the bashrc file, my friend told me this is where i need to put the script he gave me for it to run –  Johnny Williem Jun 15 '12 at 4:08
    
@JohnnyWilliem Editing the file means you need to open the file (just like you would open a regular text file on the computer) and make changes to it. In this case add a new line to call your script (or add your function). If you aren't comfortable with basic editing of files, perhaps you might want to ask someone with a bit more experience to lend you a hand until you are more used to Linux. –  Levon Jun 15 '12 at 4:10
    
Yes every piece of information on the net says open a text editor and acces the .profile or .bashrc from there, there is no such file visible in my text editor i am using gedit. I have actually just found the bashrc but cannot find the .profile –  Johnny Williem Jun 15 '12 at 5:33
show 1 more comment

The right file for environment variables such as PATH is not ~/.bashrc but ~/.profile. .bashrc is a configuration file for interactive shells; .profile is the session startup script. See Alternative to .bashrc.

Bash is a bit peculiar with its startup files: in login shells, it reads ~/.bash_profile if it exists and ~/.profile otherwise. In interactive non-login shells, it reads ~/.bashrc. There's no reason not to load interactive settings in interactive login shells, and there are many setups where the session start shell is not invoked as a login shell but ~/.profile is read explicitly. So make your ~/.bash_profile contain just these two lines:

. ~/.profile
case $- in *i*) . ~/.bashrc;; esac

If you had things in ~/.bash_profile, move them to ~/.profile if they are things like environment variable settings, and to ~/.bashrc if they are interactive shell configuration such as aliases and key bindings. Put all your PATH manipulation in ~/.profile.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.