17

There's a lot of programs out there that can utilize .env files. Most of them support the basic bash-syntax, others support more advanced things like templating within the .env files. The way you're supposed to use .env files varies a lot as well. Often in this context, you'll year from the 12-factor-app which states that you should export (some) configuration as environment variables, that apparently lead to two use cases:

  • Some dotenv programs do just that: you prefix your command on the shell with dotenv and the variables in the dotenv file will magically be available in you process.
  • Others however provide libraries that actually read .env files from within your code -- a very different approach since your code is suddenly interpreting .env files directly and does not "see" the environment variables anymore.

Since there's so many different interpretations of usage, use-cases and syntax, is there a proper definition of .env files or some commonly accepted standard? If not, at least some historical references?

Bastian Venthur
  • 12,515
  • 5
  • 44
  • 78

2 Answers2

8

It appears that .env files lack a complete definition.

This reference:

https://devcenter.heroku.com/articles/heroku-local

Links here:

http://blog.daviddollar.org/2011/05/06/introducing-foreman.html

Which leads here:

https://ddollar.github.io/foreman/

Which contains this:

ENVIRONMENT
    If a .env file exists in the current directory, the default
    environment will be read from it. This file should contain key/value
    pairs, separated by =, with one key/value pair per line.

        FOO=bar
        BAZ=qux
davejagoda
  • 2,420
  • 1
  • 20
  • 27
4

I found this link https://hexdocs.pm/dotenvy/0.2.0/dotenv-file-format.html

The escape rules worked for loading GitHub CLI secret and variable values which contained quotes (JSON).

Beyond that, I can't vouch for its accuracy, completeness, or if any given .env consumer will have the same implementation.

YMMV

EDIT

Apparently the hexdocs implementation is based on this one: https://github.com/bkeepers/dotenv

so now there are two of them.

RichyRoo
  • 373
  • 3
  • 10