Reputation: 1549
I need to set an array of strings on my .env file and cant find information about the right syntax. Test for this takes quite a while so I wanted to save some time. Some of this options should work:
MY_ARRAY=[first_string, second_string]
MY_ARRAY=[first_string second_string]
MY_ARRAY=['first_string', 'second_string']
Can someone tell me which?
Upvotes: 15
Views: 16607
Reputation: 102001
As far as I know dotenv does not allow setting anything except strings (and multiline strings). The parser syntax is:
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
The reason behind this is shell and OS support for setting other types of env variables is spotty.
You could use a separator such as commas or pipes (|) and split the string with ENV['FOO'].split('|')
. But maybe what you are trying to do should be solved with an initializer which combines ENV vars.
Upvotes: 19