[ubuntu] Setting environment variables inside a bash script

Donald R. Ziesig dziesig at adelphia.net
Sun Oct 1 23:36:28 UTC 2006


Hi Antonio!

It depends where you examine the value of FOO.

if you add the line

echo $FOO

within the bash file,  the response will be:

bar

If, on the other hand, you input the line

echo $FOO

after the bash file has exited, you will get no response.

====

Environment variables which are set within the file are local to the 
file and do not exist after the file exits.

If you want to set environment variables that exist outside the file you 
need:

<BOF>
FOO="bar"
export FOO
<EOF>

and execute the file by

. ./file.script

(in the old days, with the c-shell, that would have been "source 
file.script")

Hope this helps.

Don Ziesig

Antonio Oliveira wrote:

>Hello everyone.
>
>I am having a problem trying to set up some environment variables
>in /etc/rc.local
>
>here is my file
>
>#!/usr/bash
>
>FOO="bar"
>export FOO
>
><EOF>
>
>If I run /etc/rc.local I get absolutely no error messages, but calling env
>doesn't show the variable 'FOO' doing echo $FOO prints nothing.
>
>If I simply type {export FOO="bar"} in the bash shell and try to echo $FOO
>the variable has the correct value.
>
>What am I doing here.
>
>I'm using Edgy testing.
>
>Cheers
>--to
>
>
>  
>





More information about the ubuntu-users mailing list