Bash: Subprocess access variables Bash: Subprocess access variables bash bash

Bash: Subprocess access variables


No, it's really not. The subshell runs in an entirely separate operating system process, and the only way for two processes to share memory is for their code to set that up explicitly with system calls. Bash doesn't do that.

What you need to do is find some other way for the two processes to communicate. Temporary files named after the PIDs would be one way:

#For the RunOnIp Function to backgroundrunonip $ip $i $@ >data-tmp&mv data-tmp data-$!

And then cat the files:

#Everybody finished, so output the information from the temp filesfor x in ${PIDS[@]}; do    cat data-$x    rm data-$xdone;


You might be able to set up a named pipe to do interprocess communication.

Another possibility, in Bash 4, might be to use coprocesses.

Additional references: