Export doesnt work for a back ground process

pipe.sh

 export START=100
 . ./other.sh &
 wait

other.sh

sleep 5
export END=200

but I dont see the variable END in "export -p". But I do see it if change the pipe.sh to

 export START=100
 . ./other.sh 

how do I export variables from background process? Any work arounds?

Answers


A child process cannot change parents environment, you need to declare the variable from the parent somehow. For example using a file:

pipe.sh:

export START=100
. ./other.sh > tmp &
wait
source tmp
rm tmp 
echo $END

other.sh:

sleep 5
echo "export END=200"

Also see this answer.


Need Your Help

Getting to modify events on changes in file?

java filesystems nio

I am using Watch Service API of nio.2 classes to watch a specific directory( Ubuntu 11.10). whenever a change is made, for eg if I modify in existing file, it fires a MODIFIED event 2 times. Don't...

Singleton Service classes in c++

c# c++ dependency-injection prism mef

Coming from a .NET/C# Background and having solid exposure to PRISM, I really like the idea of having a CompositionContainer to get just this one instance of a class whenever it is needed.