What the parentheses do is open a nearly isolated subshell that can't affect the namespace of the parent process (of main.sh).
What it does execis that what follows will replace the shell.
So when you do a: (exec ./run-script.sh)it's just executing that file which doesn't actually have anything to execute. And if it had something, as it is inside a subshell, it will have no effect on the parent process, so "variable" will always have the same value declared in "main.sh".
Quick answer: for the value of the script variable to be changed you need to load that script with either source or . , (is a dot):
long answer
What the parentheses do is open a nearly isolated subshell that can't affect the namespace of the parent process (of main.sh).
What it does
exec
is that what follows will replace the shell.So when you do a:
(exec ./run-script.sh)
it's just executing that file which doesn't actually have anything to execute. And if it had something, as it is inside a subshell, it will have no effect on the parent process, so "variable" will always have the same value declared in "main.sh".