When you call script B from script A, script B runs in a separate instance of the shell. This instance receives a copy of the current environment, hence all variables from script A will be available to script B. However, once script B ends, control is returned to the shell instance running script A, and any changes script B may have made to
its environment is lost.
Solution: Rather than calling script B from script A, use the "source" command/function:
Code:
[... this is script A ...]
. ./path/to/scriptb
[... rest of script A ...]
Note the dot before the path; that's the "source" command. It cause the entire contents of script B to be "imported" into script A, and thus it will run in the same shell instance as script A.