Append dir to PATH

3

1

I'm trying to localy add a dir to the global $PATH variable. I added the following to my .bashrc.

export PATH=$PATH:$VRS/bin

But PATH seems to get concatenated to itself over & over every time I open a shell (i.e. PATH keeps growing). Any ideas?

Meir

Posted 2013-08-01T07:13:15.877

Reputation: 43

Answers

5

In your script/.bashrc, just use:

PATH=$PATH:$VRS/bin

so that the change is temporarily only for the script/shell session you're running. The export command will make the change permanent.

ADTC

Posted 2013-08-01T07:13:15.877

Reputation: 2 649

3

Indeed, each time you open a shell, your .bashrc is executed. And thus, with your current code, your PATH will grow indefinitely.

If you only need this change to path for your shell, you can just remove the export, and let in your .bashrc:

PATH=$PATH:$VRS/bin

If your need to have this change more global, move your line (and the code defining your $VRS) to file ~/.profile, but by keeping the export. This file is only executed at login, not each time your open a shell.

Or even to /etc/profile if you want this change to be for all users.

Levans

Posted 2013-08-01T07:13:15.877

Reputation: 2 010

Nice, more options than mine. I didn't think of the user profile and global profile files :) – ADTC – 2013-08-01T07:33:54.077