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.
source
command for thousands of times, I never thought about it seriously. I just tested it, the current shell will source the variables in the script whether the variable was exported or not. It's really helpful. – Searene Mar 26 '16 at 10:53