Environment variables are just ways to name pieces of text to make them easier to use across multiple programs and scripts. They are used mostly for settings and locations of files.
For example Bash and most other shells use $PATH to search for executables in a specific order when trying to run a command. Updating $PATH allows you to add custom places to check for other programs.
‘export PATH=/opt/bin:$PATH’ will update $PATH and Bash will look for executables in /opt/bin before anywhere else.
Environment variables are used quite extensively when compiling code to make it easier to pass flags to the compiler without having to type them in every time (modify defaults). They are also used in many shell scripts (uncompiled command list) so that you can change 1 line at the top of the scrips (such as a location of a log file) once instead of all over the script and reuse it.
Environment variables can contain mostly any text, and be given an arbitrary name to make sure things easier to read and update. There are tons of well known ones, and lots are used across multiple programs. These are generally documented for your specific shell and in the help for your specific program.
Latest Answers