-
-
Save tinker1987/a9382ab3561283645dd70405982550b5 to your computer and use it in GitHub Desktop.
Parse a .env (dotenv) file directly using BASH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Pass the env-vars to MYCOMMAND | |
eval $(egrep -v '^#' .env | xargs -d '\n') MYCOMMAND | |
# … or ... | |
# 2. Export the vars in .env into your shell: | |
export $(egrep -v '^#' .env | xargs -d '\n') | |
# 3. Avoid existent vars overriding | |
source <(grep -v '^#' .env | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g') | |
# 4. | |
set -o allexport | |
[[ -f .env ]] && source .env | |
set +o allexport |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment