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.
[val](#mw%5Fec0c5913-3747-483f-bb06-d2de57fd7f52) = getenv()
returns a dictionary of strings containing all environment names and values.
Examples
res = getenv("SYSTEMROOT")
val = getenv(["VarName1"; "VarName2"])
val =
2×1 string array
"VarVal1"
"VarVal2"
Input Arguments
Environment variable names, specified as a string scalar, character vector, string array, or cell array of character vectors.
Example: "PATH"
Output Arguments
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:
- If
varname
is a nonscalar string array or cell array of character vectors, thenval
has the same type and dimensions asvarname
. - If no input value is provided, then
val
is a dictionary of strings containing all environment variable names and values. - If
varname
is a string scalar, thenval
is a character vector.
Extended Capabilities
Version History
Introduced before R2006a
Get the values of multiple environment variables by usinggetenv
with a string array or cell array of character vectors as input.