Setting $PATH environment variable in Bash

Printed from http://www.compatdb.org/support/topics/4048_setting_path_environment_variable_in_bash.html

Setting $PATH environment variable in Bash - 12/29/03 02:24 AM

I have just installed MySQL and I am getting tired of having to type the full path name to start the server manually (/usr/local/mysql/bin/mysqld_safe --user=mysql). I thought I would add this path to my $PATH environment variable. So I typed the following to add this path:

Code:
PATH=$PATH":/usr/local/mysql/bin"


This works great only for the current session. If I move to another x-windows terminal (on the same machine just another window running a terminal) then the $PATH I just created isn't visible to any other terminal. So I thought I will just add this new path to my .bash_profile. Here is what my bash_profile looks like right now after adding /usr/local/mysql/bin to my path.

Code:
# .bash_profile

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

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PATH=$PATH:/usr/local/mysql/bin
BASH_ENV=$HOME/.bashrc
USERNAME="root"

export USERNAME BASH_ENV PATH


If I close the current window that I am running a terminal in and start a new terminal then you would think bash would read the .bash_profile before starting the shell. Apparently it isn't rereading the .bash_profile or I am not adding the path /usr/local/mysql/bin to my $PATH variable correctly. Does anyone see what I am doing wrong? I am aware of creating an aliase but I don't want to do it that way. I want to know what I am doing wrong here.

I want the path /usr/local/mysql/bin to be part of my path whenever I start a terminal. I am tired of typing the full path name everytime I start and stop the MySQL server.

Thanks

Re: Setting $PATH environment variable in Bash - 12/29/03 02:35 AM

Ok well I guess I should have tried this before posting. After adding a new path to my .bash_profile I decided to just logout and log back in again to see if it would see my new/modified path then. So I shutdown X-Windows and logged out. Logged back in and typed echo $PATH and BANG! the new/modified path was shown. That is great!

So the lesson learned here is that bash only reads the .bash_profile one time and that is when you first log in to the machine. Any modifications to that file do not get passed on to new terminal sessions/windows that you subsequently open. You have to completely log out and log back in. I am sure there is a way to force BASH to reread it's .bash_profile file but I don't know how. I can't even find it in the O'reilley BASH book. But hey everything is working now so I'm happy.

Re: Setting $PATH environment variable in Bash - 11/22/04 06:13 AM

The issue with the bash shell is that you either have to do what you did, log out/in which is rather cumbersome and brut force, or you can simply invoke the following command:

>source [some file containing what you want to become the profile]

in this case it would be

>source .bash_profile

I hope this helps with future reference.

Re: Setting $PATH environment variable in Bash - 11/22/04 09:44 PM

You could also make an alias to the command.

That could be kinda neat as I see you use the --user switch.