When
MYVARIABLE="abc" . ~core/script.sh
MYVARIABLE set to abc only for the duration of the source ( . ) Command. This way it will be available for code in ~core/script.sh .
When
MYVARIABLE="abc" . ~core/script.sh
it will be installed both in the region of the current shell / script and in the region of ~core/script.sh .
Try starting first, then echo $MYVARIABLE to see that it is still empty (if it is running empty). Run the last one, echo again, and you will see that its value is set in the current shell.
Edit:
Note that MYVARIABLE displayed in the ~core/script.sh in both cases here, but only because you are using a script. If you were to execute an executable file (even an executable shell script) instead, rather than its source, the behavior would be different.
MYVARIABLE=foo /usr/local/bin/some_executable
will have a variable in scope at runtime, but
MYVARIABLE=foo /usr/local/bin/some_executable
will not have a scope variable. In order for it to spread to the executable / subshell, you need to export it:
MYVARIABLE=foo export MYVARIABLE /use/local/bin/some_executable
In Bourne-derived shells newer than ksh (bash, zsh), you can combine destination and export:
export MYVARIABLE=foo
but this does not work in ksh; you need two statements.
source share