Environment variables can be loaded from a properties file in bash
testenv.properties
foo=alpha
bar=beta
This will work because input redirection happens in the current shell.
while read line; do
export $line
done < testenv.properties
This will not work because piping happens in a subshell.
cat testenv.properties | while read line; do
export $line
done
Of course, you could also make it easy for yourself by exporting the properties directly (now testenv.sh
):
export foo=alpha
export bar=beta
And inject into the current shell using
source testenv.sh
Unfortunately you can't do stuff like this
export testenv.properties # If only...
cat testenv.properties | xargs export # Would have also been nice...
You can by with the command
. file.properties
it works