Gnuru.org
Productive Linux


Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner


Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?

Issues with $PATH
5 March 2004 @ 17:41 GMT
by Paul

Setting the environment variables if my bash profile has been a bit of a challenge.

The first thing was how to extend PATH so that the bin directory in my home directory would also be searched.

As we know:

   PATH=$PATH:~/bin

is supposed to do this.

But where do I put it?

It's all solved by the bash man page which states:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

So far so good. But then then man page says:

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.

But I wanted my PATH to include ~/bin whether I logged in on the console or opened a terminal window in X.

The solution was to do what Debian (and perhaps other distributions) suggest: put 'PATH=$PATH:~/bin' in .bashrc.

Then, in .bash_profile I put:

      if [ -f ~/.bashrc ]; then
          source ~/.bashrc
      fi

Now, the PATH variable will always include ~/bin and I don't have to write the full path name for any executables in that directory!




Comments disabled