tags:

views:

61

answers:

3

I have some proxy settings that I only occasionally want to turn on, so I don't want to put them in my ~/.bash_profile. I tried putting them directly in ~/bin/set_proxy_env.sh, adding ~/bin to my PATH, and chmod +xing the script but though the script runs, the variables don't stick in my shell. Does anyone know how to get them to stick around for the rest of the shell session?

+3  A: 

In the script use

export varname=value

and also execute the script with:

source set_proxy_env.sh.

The export keyword ensures the variable is marked for automatic inclusion in the environment of subsequently executed commands. Using source to execute a script starts it with the present shell instead of launching a temporary one for the script.

Amardeep
I had the `export`; it was the `source` I was missing.
James A. Rosen
+4  A: 

Use one of:

source <file>

. <file>
mobrule
+3  A: 

Did you try this:

. ~/bin/set_proxy_env.sh

Running it by itself opens a separate subshell (I think) and sets the variable there. But then the binding is lost after exiting back into your shell. The dot at the front tells it to run it within the same shell.

Also, don't forget to export the variables you need like so: export MYVAR=value

Vivin Paliath
It's not necessary to export every variable. Only the ones you need to be visible to child processes.
Dennis Williamson
Ah yes, that's what I meant :)
Vivin Paliath