从.env文件中创建临时环境变量。

huangapple go评论55阅读模式
英文:

Create temporary env variables from .env file

问题

我有一个.env文件,其中包含以下内容:

HOST=localhost
PORT=5432
USER_NAME=postgres

我还有一些命令,我想要使用环境变量填充它们的选项。例如:

$(cat ignore/.env | xargs) psql --host=$HOST --port=$PORT --username=$USER_NAME --password

这样我就可以轻松地使用不同的环境变量运行命令,并且可以将命令提交到版本控制中,而不包含任何敏感数据。但我遇到了错误:

HOST=localhost: command not found
英文:

I have a .env file with the following:

HOST=localhost
PORT=5432
USER_NAME=postgres

I also have some commands whose options I want to populate with the environment variables. For example:

$(cat ignore/.env | xargs) psql --host=$HOST --port=$PORT --username=$USER_NAME --password

This is so I can easily run the commands with different environment vars and also check the commands into version control without any sensitive data. But I am getting the error:

HOST=localhost: command not found

答案1

得分: 2

根据 @RenaudPacalet 的评论,这个按预期工作:

(. ignore/dev.env; psql --host=$HOST --port=$PORT --username=$USER_NAME --password)


<details>
<summary>英文:</summary>

As per @RenaudPacalet &#39;s comments, this works as expected:

(. ignore/dev.env; psql --host=$HOST --port=$PORT --username=$USER_NAME --password)


</details>



huangapple
  • 本文由 发表于 2023年5月25日 20:04:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定