4
Looking at Bash scripts, I realized that variables can be created in the following ways:
script1.sh
:
variable1=Ola
export variable2="Ola de novo"
Find out more about the difference between these two ways of declaring variables. And from what I understand export would serve to make global variables.
But by running the script and trying to print the global variable variable2
, I get the same result as the local variable in my script ``variable1````
$ ./script1.sh
$ echo $variable1
$
$ echo $variable2
$
Using the command source
or using .
And by performing the same procedure above, you get as a result the printing of the two variables.
$ source script1.sh
$ echo $variable1
Ola
$ echo $variable2
Ola de novo
At this point I understood that the objective of export is not to declare global variables. What is the purpose of the export command?
This question may help you: https://stackoverflow.com/questions/1158091/defining-a-variable-with-or-without-export
– Maury Developer