Bash shells with different environment variables

bashenvironment-variables

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?

Best Answer

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

See current path:

 > echo $PATH
 /bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin

File with custom environment settings..

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

Load custom environment

 > source exports

Confirm changes.

 > env | grep '^PATH'
 PATH=/home/me/bin2012:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
Related Question