Ok so instead of hardcoding some local env variables that mirror a remote server (OpenShift server), I'd like to programmatically do it, so we don't have to keep everything up-to-date manually.
Right now I have this hardcoded in a file:
#!/usr/bin/env bash
export OPENSHIFT_MONGODB_DB_USERNAME="admin"
export OPENSHIFT_MONGODB_DB_PASSWORD="xyz"
export OPENSHIFT_MONGODB_DB_HOST="emsa-xyz-2-emsa.cloudapps.nabisco.com"
export OPENSHIFT_MONGODB_DB_PORT=60161
Instead of hardcoding, I can retrieve the "public" env variables from OpenShift with this command:
rhc env list -a <app-name>
which writes this to stdout:
NODE_ENV=jailbreak
NPM_CONFIG_PRODUCTION=true
OPENSHIFT_MONGODB_DB_HOST=emsa-xyz-2-emsa.cloudapps.nabisco.com
OPENSHIFT_MONGODB_DB_PASSWORD=xyz
OPENSHIFT_MONGODB_DB_PORT=60161
OPENSHIFT_MONGODB_DB_USERNAME=admin
does anyone know how I can take that stdout, and, in turn, export each of those variables?
I assume it would be like so - get each line and then put export
in front of it and then run bash -e "export x"
...the problem is that probably runs in a subshell and wouldn't effect the current shell?
The existing answer to this question is good and should not be lost.