This is machine translation

Translated by Microsoft



Set environment variable




setenv(name,value) sets the value of an environment variable belonging to the underlying operating system. Inputs name and value are both character vectors. If name exists as an environment variable, then setenv replaces its current value with value. If name does not exist, setenv creates an environment variable called name and assigns value to it.

setenv(name) is equivalent to setenv(name, '') and assigns a null value to the variable name. On the Microsoft® Windows® platform, this syntax is equivalent to undefining the variable. On most UNIX® platforms, it is possible to have an environment variable defined as empty.

The maximum number of characters in name is 215 - 2 (or 32766). If name contains the character =, setenv throws an error. The behavior of environment variables with = in the name is not well-defined.

On all platforms, setenv passes the name and value to the operating system unchanged. Special characters such as ;, /, :, $, %, etc. are left unexpanded and intact in the variable value.

A process that is spawned using the MATLAB® system, unix, dos, or ! functions reads the values assigned to variables using the setenv function. You can retrieve any value set with setenv by using getenv(name).


Set and retrieve a new value for the environment variable TEMP:

setenv('TEMP', 'C:\TEMP');

Append the Perl\bin folder to your system PATH variable:

setenv('PATH', [getenv('PATH') ';D:\Perl\bin']);

See Also

| | | |

Was this topic helpful?