Skip to content

Instantly share code, notes, and snippets.

@camflan
Forked from mihow/load_dotenv.sh
Created February 11, 2025 20:39
Show Gist options
  • Save camflan/e94492b44701c1e5282a93ec124711ca to your computer and use it in GitHub Desktop.
Save camflan/e94492b44701c1e5282a93ec124711ca to your computer and use it in GitHub Desktop.
Load environment variables from dotenv / .env file in Bash
# The initial version
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
# My favorite from the comments. Thanks @richarddewit & others!
set -a && source .env && set +a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment