Skip to content

Instantly share code, notes, and snippets.

@felipecwb
Last active June 6, 2019 22:17
Show Gist options
  • Save felipecwb/1798d426a4d043579da85d91d2cca05e to your computer and use it in GitHub Desktop.
Save felipecwb/1798d426a4d043579da85d91d2cca05e to your computer and use it in GitHub Desktop.
Load dotenv in shell script
load_env() {
if [ ! -f $1 ]; then
return 1
fi
echo "> Loading $2 dotenv: $1"
awk '!/^#/{if ($1 != "") {print ">> " $0}}' $1
source <(awk '!/^#/{if ($1 != "") {print "export " $0}}' $1)
}
load_env .env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment