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 +x
ing 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?
views:
61answers:
3
+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
2010-06-17 19:47:19
I had the `export`; it was the `source` I was missing.
James A. Rosen
2010-06-17 21:54:14
+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
2010-06-17 19:47:50
It's not necessary to export every variable. Only the ones you need to be visible to child processes.
Dennis Williamson
2010-06-17 20:00:51