Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 am using a dev tool which supplies a script that sets environment variables. If I source the script the environment is modified for the duration of the bash secession. In order to revert the changes made by that script I need to restart the terminal. Is there a way to do it without restarting or opening new bash session?


share|improve this question
up vote 1 down vote accepted

Do it in a subshell:

$ (. /path/to/; runtool)

If there's just a handful of environment changes, you can do them on the command line:

$ FOO=a BAR=b runtool # FOO and BAR will be set only for runtool

You can also use an actual subshell if you anticipate doing a number of things:

$ bash
$ : this is a subshell
$ . /path/to/
$ thing1
$ thing2
$ : ...
$ exit
$ : this is the original shell

You may want to include $SHLVL in your $PS1 for the latter, so it's easier to tell that you're in a subshell. I also check for a (nonstandard) environment variable $PSYS and print it if set, as a sort of "label" for the environment.

share|improve this answer
H! could you explain this $ (. /path/to/; runtool). Thanks! P.S. I need the new env vars to stay for a while and then go back to the old env. – pic11 May 4 '11 at 23:43
Enclosing something in parentheses runs it in a temporary subshell. It's kind of like a fast version of my final example, all squeezed into a single line. (The $ is the prompt in all of the above examples.) In your case, it sounds like you want the final version with the full subshell. – geekosaur May 4 '11 at 23:45
How about: type bash then set env and after dode using the dev-tool type exit? – pic11 May 4 '11 at 23:48
That is what the final example does. (As I mentioned before, the $ is the prompt / $PS1, not some special shell syntax.) – geekosaur May 4 '11 at 23:50
I see. Thanks a lot! – pic11 May 4 '11 at 23:51

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.