bash Dotenv 多行变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46147228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dotenv multiline variables
提问by Mirror318
I'm using dotenv
.
我正在使用dotenv
.
A Ruby gem to load environment variables from
.env
.
一个 Ruby gem,用于从
.env
.
Is it possible to have multiline variables in my .env
file?
我的.env
文件中是否可以有多行变量?
e.g.
例如
SOMETHING_CERTIFICATE="-----BEGIN CERTIFICATE-----
JSDFALDAFSSKLABVCXZLV2314IH4IHDFG9AYDF9DSSDF82QWEIWFHDSSD8SADF0=
-----END CERTIFICATE-----"
^ having the above just throws an error on that middle line, as if it's not part of the string and I'm trying to create an improperly formatted variable.
^ 上面的只是在中间那一行抛出一个错误,好像它不是字符串的一部分,我正在尝试创建一个格式不正确的变量。
回答by Brian
Did you try reading the documentation?
您是否尝试阅读文档?
Multi-line values
If you need multiline variables, for example private keys, you can double quote strings and use the \n character for newlines:
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9…\n-----END DSA PRIVATE KEY-----\n"
多行值
如果您需要多行变量,例如私钥,您可以双引号字符串并使用 \n 字符作为换行符:
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9...\n-----END DSA PRIVATE KEY-----\n"
回答by SaturnFromTitan
From the documentation Brian posted above:
从上面布赖恩发布的文档中:
Alternatively, multi-line values with line breaks are now supported for quoted values.
或者,现在支持带换行符的多行值用于引用值。
So the solution you sketched in your question is legit now!
所以你在问题中勾勒的解决方案现在是合法的!