Main Content

getenv

Environment variable

Description

example

val = getenv(varname) returns the value of the operating system environment variable varname. 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 a Mac platform, starting MATLAB from the Applications folder creates an environment that is different from that created by starting MATLAB from Terminal.

example

val = getenv() returns a dictionary of strings containing all environment names and values.

Examples

collapse all

res = getenv("SYSTEMROOT")
res = 'C:\windows'
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:

  • If varname is a nonscalar string array or cell array of character vectors, then val has the same type and dimensions as varname.

  • 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, then val is a character vector.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a

expand all