setting a global variable in script

Hi All,

I know to set global variable i can use export .. But take the situation like below ..

I want to set a variable in one script and access that in second script

i have done like this .. It is not working

one.sh
#!/usr/bin/ksh
echo $RISSHI
export RISSHI=1

two.sh
#!/usr/bin/ksh
echo $RISSHI
export RISSHI=2

the variable RISSHI is not changed to two when i run two.sh after one.sh
i tries to execute like . one.sh i got error...

Is there is way to share a variable between scripts?

Thanks,
Arun

Variables, or rather environment variables, belong to processes, not scripts, scripts change them but they exist with the process.

If you execute a script with "#!/bin/sh" it starts a new process to run the script in, hence a new set of environment variables, children will inherit the parent's exported variables but not the other way round.

The alternative is to run a script using "source" or ".". The down side of this is the script language has to be the same and the error handling must be consistent.

Hi Porter ..

Thanks for your reply ..
Buy i tried to run the script like
. one.sh

and tried to acess that value but the error i get was

ksh: one.sh: not found.

please let me know whatis the change i have to do

Try using a qualified path to "one.sh", either "./one.sh" or with the full directory prefixing it.