DEV Community

abdennour
abdennour

Posted on

Populate env vars from .env file with Shell

This should work

export $(cat .env | xargs)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)