Setting up Environment Variables

Hi all,
I am trying to set up some variables in a shell script. The variables contain values of various paths needed to run a java module. The problem is the variables dont seem to be setting at all.

here is what i am trying to do :

JAR_HOME=/home/was5/bdcms/scheduledjobs/lib
export JAR_HOME

JAVA_HOME=/usr/java131/bin
export JAVA_HOME

SOURCE_HOME=/home/was5/bdcms/scheduledjobs/src
export SOURCE_HOME

CLASS_PATH=.:/home/was5/bdcms/scheduledjobs/src/classes12.jar
export CLASS_PATH

echo $CLASS_PATH

------------END of code -------------

This echo prints the value correctly. Where as if i do the same from unix prompt after executing the script, the variable is always empty. I have tried all kinds of things here(including export CLASS_PATH=value and export SET CLASS_PATH=value among others) and am not able to figure the problem.

Any help or pointers are appreciated.
Thanks

Two ways to go about setting env variables.

If you need the variables only within the context of the script you are running, then this would work,

./env.sh or sh env.sh. Both invoke the env shell script you have.

If you want to retain those exported variables beyond the shell context i.e. for further use outside the script, try this

source env.sh

vino

I have a similar problem, however I want to manage all variables in a single file and as such run this file at the beginning of all scripts requiring that environment variables.

scripts1 is as follows :-
ABC="ABC"
xyz="xyz"
export EXP="EXPORT"

script2 is as follows :-
./sc1
echo $ABC
echo $xyz
echo $EXP

In your script2 you have to change your first line as follows
. ./.sc1

The sc1 script is located in the same dir as script2. Its name is sc1 and not .sc1.
Tx

Apologies, I misread your message. It works great, however the variables remain constant. I have a variable for date and time which I need it to be set at execution time of the line using the var. What I have is as follows :-
In script1 I define the var
DT=`date +"%d-%h-%y|%H:%M:%S"`

In script2 I use the var
echo ${DT}
sleep 2
echo ${DT}

I get the same value when doing this.
Thx

In this case move the DT variable assignment to script two; and set your values before and after the sleep to get different values of the DT variable. You script is working the way you have coded it to work.