If I want to inherit environment variables to child processes, i do something like:
export MYVAR=tork
Assume I have a a file site.conf
containing assignments of values (that can contain spaces) to variables:
EMAIL="dev@example.com"
FULLNAME="Master Yedi"
FOO=bar
Now I would like to process this file whenever I open a new shell (e.g. with some code in ~/.bashrc
or ~/.profile
), so that any processes started from within that newly opened shell will inherit the assignments via environmental variables.
The obvious solution would be to prefix each line in site.conf
with an export
and just source the file. However I cannot do this since the file is also read (directly) by some other applications, so the format is fixed.
I tried something like
cat site.conf | while read assignment
do
export "${assignment}"
done
But this doesn't work, for various reasons (the most important being that export
is executed in a subshell, so the variable will never be exported to the children of the calling shell).
Is there a way to programmatically export
unknown variables in bash?