Documentation Center

  • Trials
  • Product Updates

setenv

Set environment variable

Syntax

setenv(name,value)
setenv(name)

Description

setenv(name,value) sets the value of an environment variable belonging to the underlying operating system. Inputs name and value are both strings. If name already exists as an environment variable, then setenv replaces its current value with the string given in value. If name does not exist, setenv creates a new 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 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 strings to the operating system unchanged. Special characters such as ;, /, :, $, %, etc. are left unexpanded and intact in the variable value.

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

Examples

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

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

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

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

See Also

| | | |

Was this topic helpful?