Changing environment variables in a shell script?

Eric Dunbar eric.dunbar at gmail.com
Fri Apr 29 00:55:49 UTC 2005


On 4/28/05, Magnus Therning <magnus at therning.org> wrote:
> On Thu, Apr 28, 2005 at 01:03:14PM -0700, Chuk Goodin wrote:
> >I'd like to change an environment variable by running a script and then have
> >it stay changed after the script has stopped running. My script is very
> >simple:
> >
> >#!/bin/bash
> >DISPLAY=opal:1
> >export DISPLAY
> >
> >After running it, my DISPLAY variable is unchanged. If I just type the
> >last two lines (one at a time) into the command prompt, it works. Also,
> >if I check the DISPLAY variable from within the script, it shows up as
> >what I want it to be. How do I get it to change my "main" environment
> >variable?
> 
> You can do what you want by 'sourcing' your script:
> 
>  $ source script
> 
> or
> 
>  $ . script
> 
> Executing the script starts a new shell and your script is run inside it
> leaving the environment of the original shell untouched. This beahviour
> is different from MS-DOS.

Where does one insert this $ source script?

Eric.




More information about the ubuntu-users mailing list