Assign value of array ENV var in .env file

I need to install an array of strings in my .ENV file and not find information about the correct syntax. The test for this takes quite a lot of time, so I wanted to save time. Some of these 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 that?

Thanks in advance.

+4
source share
1 answer

As far as I know, dotenv doesn't allow setting anything but strings (and multi-line strings). Parser:

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 for this is shell and OS support for setting other types of env variables.

, (|), ENV['FOO'].split('|'). , , , , , ENV vars.

+5

All Articles