Saturday, May 4, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 8028  / 2 Years ago, tue, april 19, 2022, 10:58:53

How can I read an .env file and set the variables as bash variables? Currently, I'm able to read it and export them as environment variables.


If the file contains the variables:


DB_NAME=mydb
DB_PASSWORD=abcd1234

Then, DB_NAME and DB_PASSWORD will be bash variables and they will contain the respective values.


More From » command-line

 Answers
0

If a text file is formatted as


DB_NAME=mydb
DB_PASSWORD=abcd1234

then these variables can be set in the current bash shell simply by sourcing the file as:


source my_custom.env

[#829] Wednesday, April 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zebrla

Total Points: 356
Total Questions: 110
Total Answers: 120

Location: Sudan
Member since Tue, Aug 3, 2021
3 Years ago
;