Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/$ "

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

thanks Mark

share|improve this question
Is it really necessary to source a file every time you run a command? – David Z 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/ 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
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/'
share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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