SetEnvironment

SetEnvironment["var"value]
sets the value of an operating system environment variable.

SetEnvironment[{"var"value,}]
sets values for several environment variables.

DetailsDetails

  • An environment variable defined in the current session is accessible within this session or in the child processes spawned by the Wolfram System, for example, when using Run or CreateLibrary.
  • Values of environment variables, or merely their existence in the environment, may affect the behavior of certain Wolfram Language functions or child processes.
  • The value or the existence of a defined variable is not preserved when the Wolfram System is terminated or restarted.
  • If the variable did not exist in the environment, its name is added to the environment with the associated .
  • If the variable already existed in the environment, its value is replaced with .
  • Setting "var"->None removes the variable and its definition from the environment. If did not previously exist, it will not be created.
  • Setting does not remove the variable from the environment, but merely sets its value. If did not previously exist, it will be created.

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Set the HOME environment variable:

In[1]:=
Click for copyable input

Set multiple variables:

In[1]:=
Click for copyable input

Get the values of variables:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Unset the variable or remove the variable from the environment:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

Environment variables are accessible to child processes. On Windows:

In[1]:=
Click for copyable input
Out[1]=

On Unix:

In[2]:=
Click for copyable input
Out[2]=
Introduced in 2012
(9.0)