Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 want to somehow enter a different bash shell with some altered environment variables.

For example, if I run script bfin.sh and it contains something like

export PATH=/home/me/bfin2012:$PATH

I want it to create a bash shell with this changed variable. How to do this?

share|improve this question

To load environment variables you've put into a file, you can use the source command. e.g.

See current path:

 > echo $PATH

File with custom environment settings..

 > cat exports
 export PATH="/home/me/bfin2012:$PATH"
 export ...

Load custom environment

 > source exports

Confirm changes.

 > env | grep '^PATH'
share|improve this answer

You've already set the variable and exported the set variable. If you want to enter a new bash shell at this point with that variable present, you just run:


Note that the new shell's startup procedure might end up overwriting your variable, though! This could happen in .bashrc, for example.

share|improve this answer

Either change your script to end with exec bash, or run

sh -c '. bfin.sh; exec bash'

If you want to change the environment of the current shell, run

. bfin.sh

The . (dot or period) builtin executes the command from the specified script inside the same shell environment, like a function.

share|improve this answer

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.