Skip to content

Instantly share code, notes, and snippets.

@CHANG-CHING-CHUNG
Forked from mihow/load_dotenv.sh
Created September 2, 2021 03:09
Show Gist options
  • Save CHANG-CHING-CHUNG/1b3ec4adc81a5b9c5dfaef3fbf647c1e to your computer and use it in GitHub Desktop.
Save CHANG-CHING-CHUNG/1b3ec4adc81a5b9c5dfaef3fbf647c1e to your computer and use it in GitHub Desktop.
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@CHANG-CHING-CHUNG
Copy link
Author

CHANG-CHING-CHUNG commented Sep 2, 2021

.env

USER=foo
PWD=bar

some.sh

#!/bin/sh

. .env

echo $USER

exit 0

@CHANG-CHING-CHUNG
Copy link
Author

Export .env

set -a; source .env; set +a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment