I have a little script that sets my proxy system wide in one go, it calls gconftool-2, sets a proxy in ~/.ssh/config and sets the proxy for apt. This is all relatively simple. The real problem comes in updating my running bash sessions.

It is possible to run a command from the prompt ($PS1, $PROMPT_COMMAND, even binding enter to a command) - but these are all executed as separate commands - and hence have no influence on my current environment. Instead of executing these commands, I'd like to source them.

Even this doesn't work:

export PS1="\$(source /etc/profile.d/proxy.sh)$ "

I understand why it doesn't work (I think), but how can I get around it?

thanks Mark

link|improve this question
Is it really necessary to source a file every time you run a command? – David Zaslavsky Jun 28 '10 at 22:05
If I change my proxy (after having taking my laptop from work to home or back) I can either run a command in every bash session (usually a few) that I have open at that moment, or restart each and every one of them. Sourcing a small script that sets or unsets the proxy from /etc/profile.d/proxy.sh seems to me the easiest way of solving this. If anybody as an idea how to push these changes into my bash sessions .. I'm open to suggestions! – plof Jun 29 '10 at 3:54
feedback

1 Answer

up vote 2 down vote accepted

The reason what you show doesn't work, as you may have suspected is that the $() creates a subshell. Changes within a subshell don't persist to the parent and, as you say, have no influence on your current environment. However, PROMPT_COMMAND can do what you want without creating a subshell:

export PROMPT_COMMAND='source /etc/profile.d/proxy.sh'
link|improve this answer
Thanks Dennis - that worked. I had seen PROMPT_COMMAND, and I was under the impression that I had even tried this - apparently not. Thanks for your answer! – plof Jun 29 '10 at 5:14
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.