Environment variables on *nix are ... strange.
I noticed this first when I assigned TZ to .tar.xz (or .tar.gz)
as I was lazy. Then things suddenly no longer worked. Turns out
TZ is ... timezone. So you should not define all variables, right?
Well ... how to know that? People can perhaps read tons of documentation,
but I want to ... minimize time investment here. So I learn mostly
by learn-and-doing. And as far as I know there is no trivial way to
know about "this can be dangerous". Those shells are fairly simple
at all times - and not that sophisticated.
TMP versus TEMP may also be trivial but ... who can remember the
differences? And why is it important?
I have come to think that environment variables are useful; I use
them all the time. But they are a bit hackish and not super-elegant
and may have side effects. This is not a very important side effect
per se, as most people will not run into issues such as TZ or having
to think which variable to use and which not, but in the moment when
you DO get surprising results, and you don't know why, this may become
a problem suddenly. I kind of semi-work around by prefixing via:
MY_
This is even less elegant, to then have e. g.:
MY_TEMP = /home/x/temp/
or something like that. But with the prefix "MY_" I rarely
run into problems. So this then becomes my main pointer,
e. g. MY_TEMP_DIRECTORY, and then TEMP and TMP may just
be aliases to that. It's a bit stupid but it is also simple
and kind of works. Beauty is not to be found here, but it is
practical and that is not a bad thing.
In my own ruby code I also have to use ENV[] sometimes, which
is a wrapper over environment variables, but I also try to
be as independent as possible from that. For instance, all
my settings are stored in simple .yml files, and these are
then used to autogenerate environment variables or handle
things in environments where there are no environment
variables available (this is sometimes the case; I had
that issue with .cgi files many years ago, where I wanted
to access all environment variables but for a reason I
don't fully remember, this was not available. Then I
transitioned into those .yml files and that problem went
away; now of course I need to load those .yml files, if
necessary, but this is trivial in ruby, YAML.load_file()
works very well for the most part, and I find this is
more reliable than depending on reading environment
variables output. On some restricted environments this
may be unavailable though; I had that on university campus
running ancient linux systems, so I have to be flexible
in this regard).