getenv - Get environment variable - MATLAB (original) (raw)

Main Content

Syntax

Description

[val](#mw%5Fec0c5913-3747-483f-bb06-d2de57fd7f52) = getenv([varname](#d126e644015)) returns the value of the operating system environment variablevarname. If varname does not exist, then getenv returns an empty character vector.

On UNIX® platforms, the shell you use to start MATLAB® determines the operating system environment. For example, on aMac platform, starting MATLAB from the Applications folder creates an environment that is different from that created by starting MATLAB from Terminal.

example

[val](#mw%5Fec0c5913-3747-483f-bb06-d2de57fd7f52) = getenv() returns a dictionary of strings containing all environment names and values.

example

Examples

collapse all

res = getenv("SYSTEMROOT")

val = getenv(["VarName1"; "VarName2"])

val =

2×1 string array

"VarVal1"
"VarVal2"                                        

Input Arguments

collapse all

Environment variable names, specified as a string scalar, character vector, string array, or cell array of character vectors.

Example: "PATH"

Output Arguments

collapse all

Environment variable values, returned as a string scalar, character vector, string array, cell array of character vectors, or dictionary of strings. The type and dimensions of the returned output value is determined by the input value:

Extended Capabilities

Version History

Introduced before R2006a

expand all

Get the values of multiple environment variables by usinggetenv with a string array or cell array of character vectors as input.