0

I have a Red Hat Linux machine where I am not root.

In my home folder, I added this to my .bash_profile and .bashrc:

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

Then, I ran ./.bash_profile and ./.bashrc.

However, $PATH is not updated.

Any idea why this happens?

bsky
  • 19,326
  • 49
  • 155
  • 270
  • BTW, hopefully you're adding a *directory* as opposed to a file to PATH; adding the name of a file won't have any effect. And BTW, there's no need to use `export` there explicitly -- the `PATH` variable is already in the environment, so updates to it will be exported without any further action needed. – Charles Duffy Mar 03 '17 at 18:11
  • That's right a directory. I updated the question. – bsky Mar 03 '17 at 18:15
  • BTW, this is arguably duplicative of http://stackoverflow.com/questions/17852111/unable-to-export-the-variable-through-script-file – Charles Duffy Mar 03 '17 at 18:18

2 Answers2

2

When you run these files -- like when you conventionally execute any script -- they're executed in a separate shell, and changes to that shell's state (working directory, variables, etc) are lost when that shell exits. If the goal is to change the state of the interactive shell that you're operating in, you need to source them instead.

Syntax is as follows:

source .bashrc  # on extended shells such as bash only
. .bashrc       # or on any POSIX-compliant shell

The space is critical; ./.bashrc would instead be trying to run .bashrc as an executable, with its own interpreter, whereas . .bashrc is using the . command documented at http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_18 to execute the contents of the file in your current interpreter.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
0

You need to source your .bash_profile to get the changes in your current shell.

PeteH
  • 79
  • 6