Normally all shell script variables are local. If you load another copy of shell (open a new shell) by typing the command "$bash" or create a new script file, it ignores all local variables.
To set a global variable you can use "export" command. You can access global shell script variables from new shell and new script file
List all exported global variables using the command "$export -p".
Exported global variable "AGE" should be there in the list, and the local variable "NAME" will not be there.
Now i am going to create a new script file called "myscript.sh" , and i am going to display the local variable "NAME" and the global variable "AGE". Then you can understand the changes.
The output is given bellow:
In the output it will show only the global variable "AGE" not the local variable "NAME".
You can create a exported variable in two different ways. The screen shot is given bellow:
Now i am going to open a new shell (new Terminal / tab) then the exported global variable that we created is no more in the new shell. I am also going to execute the same script "myscript.sh" in new terminal.