getenv

Returns the value of an operating-system environment variable.

Category: Environment and Settings > System Commands

Syntax

v = getenv(name)

Returns the value of the variable name as a character vector.

Description

getenv reads the process environment, which includes variables changed earlier with setenv. An undefined variable is not an error; test the result with isempty, or use isenv to ask directly.

Input arguments

name
Variable name, as a character vector or string scalar.

Output arguments

v
The value. A variable that is not defined gives an empty character vector.

Example

Set and read a variable

setenv('MY_DEMO', 'abc');
v = getenv('MY_DEMO')
missing = getenv('NO_SUCH_VARIABLE_XYZ')
isempty(missing)
Output
v = 'abc'
missing = 0×0 empty char array
ans = logical
   1

See also

setenv unsetenv isenv loadenv