Search code examples
rebolred-lang

How can I read values from a configuration file (text)?


I need to read values (text) from a configuration file named .env and assign them to variables so I can use them later in my program.

The .env file contains name/value pairs and looks something like this:

ENVIRONMENT_VARIABLE_ONE = AC9157847d72b1aa5370fdef36786863d9
ENVIRONMENT_VARIABLE_TWO = 73cad721b8cad6718d469acc42ffdb1f
ENVIRONMENT_VARIABLE_THREE = +13335557777

What I have tried so far

read-values.red

Red [

]

contents: read/lines %.env

env-one: first contents
env-two: second contents
env-three: third contents

print env-one ; ENVIRONMENT_VARIABLE_ONE = AC9157847d72b1aa5370fdef36786863d9
print env-two ; ENVIRONMENT_VARIABLE_ONE = 73cad721b8cad6718d469acc42ffdb1f
print env-three ; ENVIRONMENT_VARIABLE_ONE = +13335557777

What I'm looking for

print env-one ; AC9157847d72b1aa5370fdef36786863d9
print env-two ; 73cad721b8cad6718d469acc42ffdb1f
print env-three ; +13335557777

How do I continue or change my code and parse these strings such as the env- variables will contain just the values?


Solution

  • env-one: skip find first contents " = " 3

    See help for find and skip