[英]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.我可以设置一个仅对该特定命令可用的环境变量,之后在该 shell session 中不可用。 (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 获取环境变量:
$ 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?现在,我如何结合这些技术——从 Heroku 获取环境变量并使其仅可用于单个命令运行?
This works but $FOO remains available, which is not what I want:这可行,但 $FOO 仍然可用,这不是我想要的:
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:根据您提供的 heroku 命令,这应该可以实现您想要的:
env $(heroku config:get …) ruby -e 'puts ENV["FOO"]'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.