HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free and registered users see less advertising! If you just want to browse through the existing questions, just select the forum that you want to visit from the selection below. Otherwise, click here to register!. We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Export PATH

I have been piddling around, trying to learn some shell scripting, so I decided to create a directory in my home directory to store all of my test scripts. I tried to add that directory to my $PATH with:

export PATH=$PATH:/path/to/my/directory

However, when I log out, and log back in, bash doesn't save this change. It acts like the change is only good for the current session. Did I do this wrong, or is this related to my not having a ".bash_profile" file?

Re: Export PATH

Your current method only changes the PATH for the current session. Once you log out, anything you've added to the path will be removed.

The way to modify the path variable permanently is to edit .bash_profile (assuming you are using the default bash shell).

To edit the .bash_profile, change to your home directory (IE: /home/username) and type: vi .bash_profile then arrow down until you find the line that looks similar to this:

PATH=$PATH:$HOME/bin

Type i to enter 'insert' mode, then add whatever directory you want to the end of it (remember to use the ':' between directory names). Press the escape key to exit 'insert' mode, type :w to write the file and type :q to quit the vi editor.

Re: Export PATH

The only thing I have in my /HOME directory is a .bash_history. I tried to create a .bashrc and .bash_profile manually but it didn't work, as far as recognizing my aliases. Is there something else I need to put in the file besides the aliases themselves? Do I need to tell bash to read the .bashrc file every time a terminal is opened up, or is it supposed to do that on it's own?

Re: Export PATH

Did you use vi to try to create a .bash_profile as SkyNet suggested?

The .bashrc and .bash_profile files are read at login automatically by bash. If you are using a different shell (such as ksh or csh) they won't help, but if you have a .bash_history you are using bash so these are the files you need.

You said you tried to make the .bash_profile and .bashrc manually but it didn't work as far as recognizing your aliases? I'm not sure what you mean by this, but are you trying to say you have to set your aliases every time you login now but the other problem is fixed? If that's the case you need to add your aliases to the .bashrc file.

If that's not what you meant, sorry... I wasn't sure what you meant and that was the only thing that made sense to me

Re: Export PATH

Those five lines were the only thing in the .bashrc that I created. My problem is that I don't know if I need to do something else to this file to make it work, or if I need to somehow change another file to tell bash to read this... I am just not sure if these lines are all I need to make bash use these aliases every time I start a terminal (or start up in runlevel 3).

Re: Export PATH

If you have a .bashrc and .bash_profile in your homedir it will override any settings in the global .bash_profile and .bashrc.

Did you log out and back in to test that the new .bashrc and .bash_profile worked? They won't take effect for the session you created them in, because they didn't exist when you logged in with that session. Try logging out and back in now that you have them and see if they worked.