On the Use of Environment Variables?
ender-iii asks: "The company I work for is ready for a ground up revamp of our application. The old version relies heavily on environment variables (so much so, that if they aren't set, the app core dumps!). The old
programmer wants to do the same thing and put all configuration in the environment. I am arguing for a config file. My question is this: why would anyone use environment variables for a standalone application?" I can think of lots of reasons where an environment variable for certain settings is better than having to edit a configuration file (user overrides of that setting, for example...and many time users aren't going to have write perms to config files!) however, they have the strongest value when used appropriately. If you are setting 10-20 variables in the environment, then you really should be thinking about a config file of some sort...not every admin/user will be happy cluttering their environment with unnecessary variables. What do you all consider appropriate use of ENV variables, and when is it acceptable to use it to store lots of config information?
The utility of environment variables is indicated by the name. The environment that a program runs in should have influence on its behavhior. For instance the program should decide how many columns of text to display from a config file... what if the screen has 80 columns by the config file says 40? Environment variables should describe to a program what environment it is running in. Environment variables should answer quesitons like, "what is the name of the user running me?", "what is my current working directory?", "where should I find my config file?", "what kind of terminal am I running on? do I HAVE a terminal?".
I think that there is nothing wrong with the same data being represented in a config file and the environment. In fact the best way is to have a global config file in /etc, a user specific config file (.somethingrc), and allow environment variables to override the config files. I disagree with the idea of replacing all your environment variables with a single once that just has the location of a config file. If your environment variables do indeed describe the working environment for the program then they should be in the environment.
This isn't a slight or insult or sarcasm at all; you would probably find a book on the history of unix to be of benefit. You've obviously got the wisdom to ask, "why do we need these variables" when so many others just use them for EVERYTHING or use them for NOTHING. You'll get more insight from a book drawing your own conclusions than from us here.
Oh, and if your program core dumps when a variable isn't set... that's just bad coding and you should be as suspicious as your are. :-)