dotenv-rs / dotenv

Library to help supply environment variables in testing and development
MIT License
566 stars 45 forks source link

Local Variable override #12

Closed phoenisx closed 5 years ago

phoenisx commented 5 years ago

Overriding local .env variables with system global variables, Is it intentional?

I am asking so, because there might be cases where you don't have the authority to override the system variables, but still want to use a local variable with same name in your application, where local variable should override the system variable instead.

ZoeyR commented 5 years ago

The .env format does this intentionally. This is the same for the ruby gem which this is based on. The idea is that the real environment variables are always more correct than the .env file. Can you give an example of a system where you would not be able to override the environment variables? Most systems have an idea of user-level environment variables which should override the system ones.

phoenisx commented 5 years ago

@dgriffen I was trying to use https://developer.oxforddictionaries.com/ api, where I was using LANG as an .env variable set to en, while the linux system overrides it by en_US.UTF-8.

ZoeyR commented 5 years ago

In this case your options are to set it for the specific process (e.g. LANG="en" ./your-binary) or use a different name for the variable. If you're using running this binary as a specialized user you could also override the environment variable for that user.