The title pretty much says it all..
Suppose I have a bash script:
# do some magic here, perhaps fetch something with wget, and then:
if [ "$VAR1" = "foo" ]; then
# and potentially many other vars...
# run the bash script somehow
Certainly! It just requires some hacks:
variables = subprocess.Popen( ["bash", "-c", "trap 'env' exit; source \"$1\" > /dev/null 2>&1", "_", "yourscript"], shell=False, stdout=subprocess.PIPE).communicate()
This will run your unmodified script and give you all exported variables in the form
foo=bar on different lines.
On supported OS (like GNU) you can
trap 'env -0' exit to get
\0 separated variables, to support multiline values.