Exporting a variable is one way only. The exported variable will have the correct value for all child processes of your shell, but when the child exits, the changed value is lost for the parent process. Actually, the parent process will only see the initial value of the variable.
Which is a good thing. Because all child processes can potentially change the value of an exported variable, potentially messing things up for the other child processes (if changing the value would be bi-directional).
You could do one of two things:
- Have the script save the value to a file before exiting, and
reading it from the file when starting
- Use
source your-script.bash or . your-script.bash. This way, your
shell will not create a child process, and the variable gets changed in
same process
echo "$x" > myfileand to load usex=$(cat myfile)