Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

setenv

Set environment variable

Syntax

setenv(name,value)
setenv(name)

Description

example

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

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

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

setenv(name) assigns a null value to name. This syntax is equivalent to setenv(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.

Examples

collapse all

setenv('TEMP','C:\TEMP');
getenv('TEMP')
ans = 'C:\TEMP'
setenv('PATH', [getenv('PATH') ';D:\mypath']);

Input Arguments

collapse all

Environment variable name, specified as a character vector.

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

Example: 'PATH'

Environment variable value, specified as a character vector.

Example: 'C:\TEMP'

Introduced before R2006a

Was this topic helpful?