Populate env vars from .env file with Shell

This should work

export $(cat .env | xargs)

But not all time namely if it includes some comments and you are running it with sh (not bash)

Then, mitigate this issue by using instead:

export $(cat .env | sed ‘s@#.*@@’| tr -d ” | xargs)


This content originally appeared on DEV Community and was authored by abdennour

This should work

export $(cat .env | xargs)

But not all time namely if it includes some comments and you are running it with sh (not bash)

Then, mitigate this issue by using instead:

export $(cat .env | sed 's@#.*@@'| tr -d '' | xargs)


This content originally appeared on DEV Community and was authored by abdennour


Print Share Comment Cite Upload Translate Updates
APA

abdennour | Sciencx (2021-07-18T08:05:37+00:00) Populate env vars from .env file with Shell. Retrieved from https://www.scien.cx/2021/07/18/populate-env-vars-from-env-file-with-shell/

MLA
" » Populate env vars from .env file with Shell." abdennour | Sciencx - Sunday July 18, 2021, https://www.scien.cx/2021/07/18/populate-env-vars-from-env-file-with-shell/
HARVARD
abdennour | Sciencx Sunday July 18, 2021 » Populate env vars from .env file with Shell., viewed ,<https://www.scien.cx/2021/07/18/populate-env-vars-from-env-file-with-shell/>
VANCOUVER
abdennour | Sciencx - » Populate env vars from .env file with Shell. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/18/populate-env-vars-from-env-file-with-shell/
CHICAGO
" » Populate env vars from .env file with Shell." abdennour | Sciencx - Accessed . https://www.scien.cx/2021/07/18/populate-env-vars-from-env-file-with-shell/
IEEE
" » Populate env vars from .env file with Shell." abdennour | Sciencx [Online]. Available: https://www.scien.cx/2021/07/18/populate-env-vars-from-env-file-with-shell/. [Accessed: ]
rf:citation
» Populate env vars from .env file with Shell | abdennour | Sciencx | https://www.scien.cx/2021/07/18/populate-env-vars-from-env-file-with-shell/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.