Henrik N
Henrik N

Reputation: 16294

How can I set environment variables from Heroku for a single bash command, not for the whole shell session?

I can set an environment variable that is only available to that specific command, and doesn't remain available in that shell session afterwards. (I'm sure my terminology is not accurate here – please correct me.)

$ FOO=hello ruby -e 'puts ENV["FOO"]'
hello
$ echo $FOO
(no output)

I can also get environment variables from Heroku:

$ heroku config:get --shell FOO BAR
FOO=hello
BAR=goodbye

Now, how can I combine these techniques – getting environment variables from Heroku and making them available only to a single command run?

This works but $FOO remains available, which is not what I want:

export `heroku config:get --shell FOO BAR`
echo $FOO

So what I want to achieve is this:

$ some_shell_magic(`heroku config:get …`) ruby -e 'puts ENV["FOO"]'
hello

Any ideas?

The underlying use case is to be able to run certain commands from a developer machine, using production config values, but not leaving those values around because they could accidentally end up being used by some other command later.

Upvotes: 0

Views: 167

Answers (1)

Philippe
Philippe

Reputation: 26840

Based on what you gave as heroku command, this should achieve what you wanted :

env $(heroku config:get …) ruby -e 'puts ENV["FOO"]'

Upvotes: 1

Related Questions