I want export variable from file. here's my file
cat file.txt
VERSION=1.0.0
LOCATION=USA
NAME=sample
ENVIRONMENT=$ENV
I export all variable on that file using this while loop
while read vars; do export $vars;done < file.txt
all variable is successfully exported, except ENVIRONMENT
i got this value, ENVIRONMENT=$ENV
(expected value is ENVIRONMENT=staging
) .
printenv | grep ^ENV
ENV=staging
my question is, why substitute it's not working when using while loop
, but its working if we manually export (e.g export ENVIRONMENT=$ENV)
??
actually there's many ways, to export variable from file, for example I can use envsubst < file > file1
and then do the while loop
, but I just need explanation for case above.