Skip to content

Instantly share code, notes, and snippets.

@GLMeece
Last active November 17, 2022 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GLMeece/41cfa15efb2917dea6f3d4c98f1e1f73 to your computer and use it in GitHub Desktop.
Save GLMeece/41cfa15efb2917dea6f3d4c98f1e1f73 to your computer and use it in GitHub Desktop.
Exporting INI file values as Environmental Variables
# It is assumed that $HOME is already defined and exported...
# Assuming within our home directory,
# we have a hidden directory called '.env'
envvarsdir="/.env/"
# ...and within that directory we had a file named 'secret_vars.ini'...
envvarsfile=secret_vars.ini
# ...we'd build the path
envvarspath=$HOME$envvarsdir$envvarsfile
if [ -f "$envvarspath" ]
then
set -a
source $envvarspath
set +a
fi
# Example key/value pairs in an INI file...
FOO=bar
MYPASS=12345
MYTOKEN=nZNyM-JksGszq-FzHEoh
preceding_spaces_are_ok=if_you_are_ok_with_them
# Commented lines are ignored.
# space_after_equals_sign = will_not_work
# Also, sorry - no section names allowed!
# DON'T! -> [my_fancy_section_name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment