esturniolo
esturniolo

Reputation: 31

How to fill variables in a bash script from another txt file, like .env in docker?

I've a template bash script with N variables that I need to change when someone ask for it. To preserve the code and avoid any stupid mistake, I like to send those variables from another file. Like everyone on does with an .env file in Docker.

So if I've the following...

Template script:

varName= 
varLastname=
varURLProfile=

...can I use a .txt file like this to pass the variables from here to previous the script to keep it intact?

.txt file:

varName= foo
varLastname= bar
varURLTwitter= https://twitter.com/foobar

How?

Thanks in advance!

Upvotes: 1

Views: 175

Answers (1)

M-Jack
M-Jack

Reputation: 393

Sure ! You can use . or source to do that :

source dotEnvFile.txt myScript or . dotEnvFile.txt myScript

Just make sure not to have a white caracter in your variable definition. Not varName= foo but varName=foo

Upvotes: 1

Related Questions