英文:
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 's comments, this works as expected:
(. ignore/dev.env; psql --host=$HOST --port=$PORT --username=$USER_NAME --password)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论