This is the only way I know what you want:
In foo.sh you have:
#!/bin/bash echo MYVAR=abc123
And when you want to get the value of a variable, you should do the following:
$ eval "$(foo.sh)" # assuming foo.sh is in your $PATH $ echo $MYVAR #==> abc123
Depending on what you want to do and how you want to do it, you can use the Douglas Leader’s suggestion to use the source, but it will be the source of the whole file, functions and everything. Using eval, only material that receives an echo will be evaluated.
Jeremy cantrell
source share