Created
October 15, 2012 22:38
-
-
Save kristjan/3896117 to your computer and use it in GitHub Desktop.
Load a .env file into your current shell. Handy when you need to skirt Foreman.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadenv() { | |
env=${1:-.env} | |
echo Loading $env | |
file=`mktemp -t tmp` | |
if [ -f $env ]; then | |
cat $env | while read line; do | |
echo export $line >> $file | |
done | |
source $file | |
else | |
echo No file $env | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could probably do this without a tmpfile, like so:
The
-s
test also makes sure it's readable. I've also really enjoyed direnv for this sort of thing.