0

I have two scripts:

#!/bin/bash
./variable2.sh
echo "11111111"
env | grep TEST_ID

and:

#!/bin/bash
export TEST_ID=1234567890
echo "222222222"
env | grep TEST_ID

Result of running it is:

./variable.sh
222222222
TEST_ID=1234567890
11111111

So looks like if script2 sets variables, they are not seen in script which is running it.. Anyone know how to solve this issue ? Thanks

FrancMo
  • 2,459
  • 2
  • 19
  • 39
  • 3
    A basic principle of Unix is that a child process cannot alter the environment of its parent. Therefore, the behavior you see is correct. If you wanted the definition of of `TEST_ID` to persist, you should not _execute_ `variable2.sh`, you should _source_ it. – John1024 Nov 29 '17 at 11:15
  • 4
    If you run `source ./variable2.sh` then variables will be seen be calling script also. – anubhava Nov 29 '17 at 11:15
  • Possible duplicate: [What is the difference between `sh` and `source`?](https://stackoverflow.com/questions/13786499/what-is-the-difference-between-sh-and-source). – John1024 Nov 29 '17 at 21:07

0 Answers0