Environment Variables in Minitab
Environment variables are a universal mechanism for conveying configuration information to Unix programs. Let’s look at how to set, get, and list environment variables in Java.
Running the program shows that we pick up the value for FOO
that we set in the program, but that BAR
is null.
The list of keys in the environment will depend on your particular machine.
If we set BAR
in the environment first, the running program picks that value up.
Note that in Java, System.setProperty()
sets a system property, which is different from an environment variable. Environment variables are typically set outside of the Java program and cannot be modified at runtime. The System.getenv()
method retrieves environment variables, while System.getProperty()
retrieves system properties.
To actually set an environment variable in Java, you would need to use a platform-specific method or execute a system command, which is generally not recommended as it can affect other processes on the system.