简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM