1 person found this helpful
Unfortunately Unix or Linux does not have a concept of dynamic system kernel or global variables.
Environment variables can be exported from a parent to a child processes, similar to copying, but a child process cannot change the shell environment of its parent process.
However, there are a few ways you could use: You can source execute the scripts, using the Bash source command or by typing . space filename. When source executing a script, the content of the script are run in the current shell, similar to typing the commands at the command prompt.
Use shell functions instead of forking shell scripts.
Store the output of a script into a variable. For instance:
It all depends on how much data you need to return. If it is only one variable, you can do this:
i=0 export I
while true; do
echo "i=$i" >&2
echo `eval $i + 1`
In other words, you can export the variables in script #1 and then parse the output of script #2. Since script #2 is a child of script #1, script #2 inherits the exported shell variables from script #1.