When to use environment variable or command line parameter?
In most of the scripts I write, I allow both with the command line parameters taking preference. This is to allow ‘lazy’ users who want to set’n’forget the parameters to do so. It also allows over-riding of those parameters in special cases by the command line. For those that don’t want to take the chance that their parameters might be set up incorrectly, they can just use parameters. Sometimes I’ll even have more levels in the hierarchy, in order of precedence: • Value set while program running. • Command-line parameter. • Environment variable. • Local config file. • Global config file. • Default. That way, for each variable, you just work your way up that list, setting it to the relevant value, if it’s there.