Skip to content

Environment variables loading with escaped quotes #20

Open
@monting

Description

@monting

Firstly, thank you so much for this amazing resource!

Onto the issue. When I insert this code:

try do # wrap in "try do"
File.stream!("./.env") # in case .env file does not exist.
|> Stream.map(&String.trim_trailing/1) # remove excess whitespace
|> Enum.each(fn line -> line # loop through each line
|> String.replace("export ", "") # remove "export" from line
|> String.split("=", parts: 2) # split on *first* "=" (equals sign)
|> Enum.reduce(fn(value, key) -> # stackoverflow.com/q/33055834/1148249
System.put_env(key, value) # set each environment variable
end)
end)
rescue
_ -> IO.puts "no .env file found!"
end

and have (double/single) quotes around the values in the .env file, the environment variables are loaded with the quotes.

For example, in the .env file:

export SOME_ENV_VAR="randomString"

results in:

iex(3)> System.get_env("SOME_ENV_VAR")
"\"randomString\""

I'm not entirely sure why there's code to load the environment variables like this. Why not just do the standard source .env?

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requestedtechnical

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions