I have a simple bash script that is using a config.ini file that looks like this:
[a]
b=1
c=2
...
In the bash script, I sometimes do eval "$(cat config_file | ./print_to_env_variables.py)"
where the python script is this:
config = ConfigParser()
config.readfp(sys.stdin)
for sction in config.sections():
print('declare -A {}'.format(sction))
for k, v in config.items(sction):
print("{}[{}]={}'.format(sction, k ,v))
Now, what this script does, is to add all sections into env variables, allowing me to use them from bash like this: echo "${a[b]}"
This only works if I do it like:
- eval...
- check the variable
but if I:
- call a function that does the eval (less code dup)
- check...
The variable does not exist.
Why is that?