Skip to content

Instantly share code, notes, and snippets.

@deviationist
Last active November 26, 2023 03:44
Show Gist options
  • Select an option

  • Save deviationist/94a061ad8fba1a1a8f41771edf73dc4b to your computer and use it in GitHub Desktop.

Select an option

Save deviationist/94a061ad8fba1a1a8f41771edf73dc4b to your computer and use it in GitHub Desktop.
Read .env-files in bash
if [ -f .env ]
then
# export $(cat .env | grep 'DB_HOST' | xargs) # Read specific line
# export $(cat .env | grep 'DB_HOST|DB_USERNAME|DB_PASSWORD' | xargs) # Read specific lines
export $(cat .env | xargs) # Read all lines
else
echo "Error: could not read .env-file" && exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment