0

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.

Searene
  • 4,550

2 Answers2

1

export is to allow subshells to inherit the variable, it does nothing to allow a subshell to change a value in the parent.

ubfan1
  • 19,049
1

For it to change your current shell environment, run the script with either

. test.sh

or

source test.sh
jlliagre
  • 5,983