Setting $PATH environment variable in Bash

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...




Topic Options
#4048 - 12/29/03 02:24 AM Setting $PATH environment variable in Bash
frequencydrive Offline
stranger

Registered: 11/25/03
Posts: 7
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

Top
Advertisement
#4049 - 12/29/03 02:35 AM Re: Setting $PATH environment variable in Bash
frequencydrive Offline
stranger

Registered: 11/25/03
Posts: 7
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.

Top
#150830 - 11/22/04 06:13 AM Re: Setting $PATH environment variable in Bash
mavrukin Offline
stranger

Registered: 11/22/04
Posts: 1
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.

Top
#150886 - 11/22/04 09:44 PM Re: Setting $PATH environment variable in Bash
CrazyKillerMan Offline
old hand

Registered: 10/14/00
Posts: 761
You could also make an alias to the command.

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

Top


Forums
Windows Support Forums
Everything New Technology
Legacy OS
Hardware
Software
Games
Networking
Customization & Tweaking
Security

Linux Support Forums
Everything Linux
Linux Hardware
Linux Software
Linux Games
Linux Networking
Linux Customization & Tweaking
Linux Security

Apple Support Forums
Everything Apple
Recent Topics
FOR SALE BRAND NEW UNLOCKED NOKIA E75
by rachy
29 minutes 48 seconds ago
FOR SALE BRAND NEW APPLE IPHONE 32GB 3GS
by rachy
36 minutes 3 seconds ago
Best setup for LAMP?
by Elder Usr
07/01/09 10:49 PM
OOo macro SQLException
by xtoph
06/28/09 12:06 PM
Decrease tooltip/infotip delay?
by firebo14
06/27/09 04:59 PM
Who's Online
1 Registered (rachy), 259 Guests and 32 Spiders online.
Key: Admin, Global Mod, Mod
Forum Stats
90532 Members
24 Forums
52157 Topics
182376 Posts

Max Online: 1079 @ 03/12/08 01:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22