Created
July 11, 2016 03:53
-
-
Save ierceg/853aabaf83e314b0be3bc25b598144ab to your computer and use it in GitHub Desktop.
Export envvars from docker-like envvar file
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
#!/bin/bash | |
# As seen here https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced | |
if [[ $0 == $BASH_SOURCE ]]; then | |
echo 'You must run this script as `source export_envvars.sh` for it to export the envvars.' | |
else | |
if [[ -z $1 ]]; then | |
echo 'You must provide name of the envvars file.' | |
else | |
# As seen here http://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable | |
# Read all the stuff from envvars file and echo it | |
while read -r line || [[ -n $line ]] | |
do | |
envvar="$line" | |
if [[ -n "$envvar" ]]; then | |
export "$envvar" | |
fi | |
done < "$1" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment