Last active
June 27, 2018 13:34
-
-
Save radmen/36327394d6b96604e03e4c61b463a5b5 to your computer and use it in GitHub Desktop.
Python: export selected env variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import os | |
parser = argparse.ArgumentParser(description='Export selected env variables.') | |
parser.add_argument('name', nargs='+', | |
help='name of env variable') | |
args = parser.parse_args() | |
def env_to_tuple (envName): | |
return (envName, os.environ[envName]) | |
namesList = vars(args)['name'] | |
for name in namesList: | |
# Escape symbols commonly used by Bash. | |
value = os.environ[name].replace('"', '\\"').replace('$', '\\$').replace('`', '\\`') | |
print('{}={}'.format( | |
name, | |
value | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment