Read from .env file and set as bash variables

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.

0

1 Answer

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
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like