Skip to content

Instantly share code, notes, and snippets.

@pulkitsinghal
Last active June 16, 2018 06:16
Show Gist options
  • Save pulkitsinghal/e37823df90e6f87f3d3f25b1cfe1cdc0 to your computer and use it in GitHub Desktop.
Save pulkitsinghal/e37823df90e6f87f3d3f25b1cfe1cdc0 to your computer and use it in GitHub Desktop.
Read the .env file and setup the environment variables for local testing
#!/bin/sh
# This script is used to read the .env file and setup the enviroment variables for local testing
echo "###"
echo Its best to invoke this script as: '. ./setenv.sh' rather than './setenv.sh'
echo "###"
while read kv
do
key=${kv%%=*}
val=${kv#*=}
if [[ "$key" == \#* ]]; then
echo skipping comments
elif [[ "$key" == "" ]]; then
echo skipping empty line
else
echo export $key="$val"
export $key="$val"
fi
done < ".env"
echo "###"
echo Its best to invoke this script as: '. ./setenv.sh' rather than './setenv.sh'
echo "###"
@pulkitsinghal
Copy link
Author

@kamal0808 - i fixed the env file reader, I may not be able to check it into our work projects for a while so please use it from over here by copy/pasting when you need it.

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