-
-
Save rochacbruno/016b344c970c80871a4ceb810f42161b to your computer and use it in GitHub Desktop.
Parse a .env (dotenv) file directly using BASH
This file contains hidden or 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
# Pass the env-vars to MYCOMMAND | |
eval $(egrep -v '^#' .env | xargs) MYCOMMAND | |
# … or ... | |
# Export the vars in .env into your shell: | |
export $(egrep -v '^#' .env | xargs) | |
# set variables from .compose.env but don't override existing exported vars | |
eval "$(grep -v '^#' .compose.env | sed -E 's|^(.+)=(.*)$|export \1=${\1:-\2}|g' | xargs -L 1)" | |
# Load up .env | |
set -o allexport | |
[[ -f .env ]] && source .env | |
set +o allexport | |
# or | |
set -a | |
[ -f .env ] && . .env | |
set +a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment