2

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

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

2 Answers2

1

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.

Levon
  • 11,384
  • 4
  • 45
  • 41
  • 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 04:06
  • @JohnnyWilliem You have to be a bit more specific - what part makes no sense? – Levon Jun 15 '12 at 04: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 04: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 04: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 05:33
  • @JohnnyWilliem - don't worry that you can't find .profile - it just means it hasn't been created yet, and that's absolutely fine. If you need to create it, go right ahead and use gedit's tools to do so. – D_Bye Jun 15 '12 at 09:38
0

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 Is there a ".bashrc" equivalent file read by all shells?.

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.