eval $(python parse_yaml.py example_file.yaml)
In this example the following variables are accessible:
$key1
$key2_nested
key1: 'test' | |
key2: | |
nested: 1 |
#!/usr/bin/python | |
import sys | |
import yaml | |
def parse(obj, base_prefix=''): | |
for key in obj: | |
value = obj[key] | |
prefix = '{}_{}'.format(base_prefix, key) | |
if type(value) == dict: | |
parse(value, prefix) | |
else: | |
print('{}="{}"'.format(prefix, value)[1:]) | |
if __name__ == '__main__': | |
with open(sys.argv[1], 'r') as f: | |
parse(yaml.load(f)) |