export and access env variable in two scripts

Hi,

I have two scripts say one.sh and two.sh.
I want one.sh to continuously export a variable in loop. and when two.sh starts then it should read the last value exported from one.sh.

file: one.sh

#! bin/sh
for i in `seq 1 1 4000000`; do
export VAR=$(($i**$i)) ;
done

file two.sh

#! bin/bash
echo $VAR ;

I am running 1st script in background as sh one.sh &
and starting two.sh .Then two.sh is not printing the vale of VAR exported from one.sh.

Please guide me on how this can be done.

Thanks !

your shell might not support your export in one step : do it it two steps (or switch to ksh) :

VAR=$(($i**$i))
export VAR

Maybe i am wrong, but i think, the variable is stored in a process/user context. So you must have processes dependencies to be able to inherit the access to environment variable, if your 2 processes are launched independantly from eachother they exectue in their own context and won't** be able to share the variable.
Maybe you should try to call the second shell from the first one so it can inherit from the parent process environment.

(**) unless they are designed storing their env in a shared memory part to which anybody have an access which might be a security weakness.

When you execute one.sh, you're executing it in a new shell. If you want to export it in current shell, then use '.' or source.

$ . ./one.sh