This is my
.env.test
S3_READY_MESSAGE="s3 is ready"
NGINX_READY_MESSAGE="nginx is ready"
Bash to output variables
$ echo $(cat ../../../.env.test | grep -o -E '^[^#]+')
output:
S3_READY_MESSAGE="s3 is ready" NGINX_READY_MESSAGE="nginx is ready"
Bash to export variables
export $(cat ../../../.env.test | grep -o -E '^[^#]+')
error
bash: export: `ready"': not a valid identifier
bash: export: `ready"': not a valid identifier
2
Answers
I originally had a solution which exported fine but it doesn't work with quoted content that has spaces.
solution 1 - CON: only works with no spaces in value
.env
solution 2 CON: Uses eval, so may be deemed unsafe.
(As long as I am doing this manually then I know the file I'm exporting so don't mind using eval in this case.)
For this particular sample input you can make use of
bash's
set -a/+a
in conjunction with sourcing.env.test
:Results: