Last active
February 24, 2020 15:57
-
-
Save antonagestam/e4889bc5059b1f1c39e53cc9612c2250 to your computer and use it in GitHub Desktop.
Make bash export statements from docker env file
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
""" | |
$ python3 export.py <(echo -e '# this is a comment\nKEY=value123') | |
export KEY='value123' | |
$ (. <(python3 export.py <(echo 'KEY=value123')) && echo $KEY) | |
value123 | |
""" | |
import re | |
import fileinput | |
pattern = re.compile("^(?P<key>[A-z_]+)=(?P<value>.+)$", re.M) | |
for line in fileinput.input(): | |
if match := pattern.fullmatch(line.strip()): | |
print(f"export {match.group('key')}='{match.group('value')}'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment