将数组值分配给 .env 文件上的 ENV var
assign array value to ENV var on .env file
我需要在我的 .env 文件中设置一个字符串数组,但找不到有关正确语法的信息。对此进行测试需要很长时间,所以我想节省一些时间。其中一些选项应该有效:
MY_ARRAY=[first_string, second_string]
MY_ARRAY=[first_string second_string]
MY_ARRAY=['first_string', 'second_string']
谁能告诉我是哪个?
据我所知,dotenv 不允许设置除字符串(和多行字符串)以外的任何内容。解析器语法是:
LINE = /
\A
(?:export\s+)? # optional export
([\w\.]+) # key
(?:\s*=\s*|:\s+?) # separator
( # optional value begin
'(?:\'|[^'])*' # single quoted value
| # or
"(?:\"|[^"])*" # double quoted value
| # or
[^#\n]+ # unquoted value
)? # value end
(?:\s*\#.*)? # optional comment
\z
/x
这背后的原因是 shell 和 OS 支持设置其他 types of env variables is spotty。
您可以使用逗号或竖线 (|) 等分隔符,并用 ENV['FOO'].split('|')
分隔字符串。但也许你正在尝试做的事情应该用结合 ENV 变量的初始化程序来解决。
我需要在我的 .env 文件中设置一个字符串数组,但找不到有关正确语法的信息。对此进行测试需要很长时间,所以我想节省一些时间。其中一些选项应该有效:
MY_ARRAY=[first_string, second_string]
MY_ARRAY=[first_string second_string]
MY_ARRAY=['first_string', 'second_string']
谁能告诉我是哪个?
据我所知,dotenv 不允许设置除字符串(和多行字符串)以外的任何内容。解析器语法是:
LINE = /
\A
(?:export\s+)? # optional export
([\w\.]+) # key
(?:\s*=\s*|:\s+?) # separator
( # optional value begin
'(?:\'|[^'])*' # single quoted value
| # or
"(?:\"|[^"])*" # double quoted value
| # or
[^#\n]+ # unquoted value
)? # value end
(?:\s*\#.*)? # optional comment
\z
/x
这背后的原因是 shell 和 OS 支持设置其他 types of env variables is spotty。
您可以使用逗号或竖线 (|) 等分隔符,并用 ENV['FOO'].split('|')
分隔字符串。但也许你正在尝试做的事情应该用结合 ENV 变量的初始化程序来解决。