Environment Variables in Wolfram Language
Our program demonstrates how to work with environment variables. Environment variables are a universal mechanism for conveying configuration information to programs. Let’s look at how to set, get, and list environment variables.
Running the program shows that we pick up the value for FOO
that we set in the program, but that BAR
is $Failed (Mathematica’s equivalent of not found or 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. In Mathematica, you can set environment variables before running the script using the SetEnvironment
function:
This would produce output like:
In Mathematica, environment variables persist only for the duration of the kernel session. To set environment variables that persist beyond the current session, you would need to modify system settings outside of Mathematica.