A load a dotenv file.

Export the vars in .env file into your shell.

Simple

export $(< .env) | xargs)

Check if it exists first and ignore comments.

if [ -f .env ]; then
  export $(egrep -v '^#' .env | xargs)
fi

Gist source

See also in my cookbook: