test.sh:
#!/bin/bash
export test_var=1
Run the script, then continue to run the command in the terminal: echo $test_var, I got nothing. Why? Since test_var was exported, I thought I could continue to use the variable in the terminal.
test.sh:
#!/bin/bash
export test_var=1
Run the script, then continue to run the command in the terminal: echo $test_var, I got nothing. Why? Since test_var was exported, I thought I could continue to use the variable in the terminal.
export is to allow subshells to inherit the variable, it does nothing to allow a subshell to change a value in the parent.
For it to change your current shell environment, run the script with either
. test.sh
or
source test.sh