Skip to content

Instantly share code, notes, and snippets.

@jlejeune
Created February 7, 2018 09:33
Show Gist options
  • Save jlejeune/cb5d3d484ff40967bda76e8eebc64dfd to your computer and use it in GitHub Desktop.
Save jlejeune/cb5d3d484ff40967bda76e8eebc64dfd to your computer and use it in GitHub Desktop.
Sourcing a shell script
from subprocess import Popen, PIPE
from os import environ
def source(script, update=1):
pipe = Popen(". %s; env" % script, stdout=PIPE, shell=True)
data = pipe.communicate()[0]
env = dict((line.split("=", 1) for line in data.splitlines()))
if update:
environ.update(env)
return env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment