In scripts, you can source the sub-shell. All variables defined in the sub-shell will be visible in the parent.
/tmp/parent.sh
Code:
#!/bin/bash
. /tmp/subshell.sh
echo $MYVAR
/tmp/subshell.sh
Code:
#!/bin/bash
echo $MYVAR
MYVAR=othervalue
execution output
Code:
bash-3.1$ /tmp/parent.sh
othervalue
bash-3.1$