setting some variables

i have a file .NAME

export MY_NAME=JOE

when i do this at the command prompt

#. .NAME
$echo MY_NAME
$JOE

i created a script called Run.sh

 . .NAME

At the command prompt i did

#sh Run.sh
#echo $MY_NAME

it returns nothing. What have i missed out?

If you want the variable to be displayed when you run "RUN.sh" , you need to source the "RUN.sh" script also.

mv run.sh .run.sh

sh .run.sh

and it would do the needful.

Hi nua7,

i tried your suggestion, its still not working.

Which shell are you using? Really shouldn't make a difference since this is common for all the shells.

I tried doing it and it is succesful in displaying the variable MY_NAME.

Can you show me your steps with the output..?

Hi new2ss,

I believe that u wont get the output if u run

sh Run.sh or sh .run.sh

as the new variable will be set only in the shell created for Run.sh and the shell wud terminate once the execution of run.sh is over

so, if u want to achieve the result then u shld run like

. Run.sh or . .run.sh

Hi, i am using bash shell.

the output was exactly the same as what i posted earlier.

Hi quintet,

your suggestion worked. Thanks. Because i need to set it as a cronjob,
would typeing . run.sh at the crontab entry work?

Hi nua, i realised my mistake. My initial run.sh script was

. Name

I ran the script and after that did a echo $NAME at the command promot.Nothing was printed.

I rewrote the code

.Name
echo $NAME

and ran again, JOE was printed. In the first case, echo $NAME yielded nothing because it was only executed after the run.sh was executed;hence whatever variables inherited could have been/probably lost.Since they are only valid for the lifetime of the run.sh script. In the second example, echo $NAME was done within the script.Therefore whatever variables inherited will still be valid.