RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • addpath
    • cd
    • copyfile
    • delete
    • dir
    • exist
    • fileattrib
    • fileparts
    • fullfile
    • genpath
    • getenv
    • getpref
    • isenv
    • isfile
    • isfolder
    • ispref
    • ls
    • matlabroot
    • memmapfile
    • mkdir
    • movefile
    • open
    • opentoline
    • path
    • pathsep
    • pcode
    • pwd
    • readstruct
    • rehash
    • restoredefaultpath
    • rmdir
    • rmpath
    • run
    • savepath
    • setenv
    • setpref
    • system
    • tempdir
    • tempname
    • uigetdir
    • uigetfile
    • uiputfile
    • unsetenv
    • userpath
    • what
    • winqueryreg
    • xmlread
    • xmlwrite

getenv — Read environment variables in MATLAB and RunMat.

getenv(name) returns the value of environment variable name visible to the current process. Calling getenv with no arguments returns a dictionary of string names and values.

Syntax

env = getenv()
value = getenv(NAME)

Inputs

NameTypeRequiredDefaultDescription
NAMEAnyYes—Variable name query: char vector, string scalar/array, or cell array of char/string scalars.

Returns

NameTypeDescription
envAnyStructure containing all visible environment variables.
valueAnyResolved environment value(s) matching NAME input shape/type.

Errors

IdentifierWhenMessage
—More than one input argument is supplied.getenv: too many input arguments
—NAME input type is unsupported for getenv queries.getenv: NAME must be a character vector, string scalar, string array, or cell array of character vectors
—Cell NAME entries are not character vectors or string scalars.getenv: cell array elements must be character vectors or string scalars
—Internal conversion of environment query outputs fails.getenv: internal conversion failure

How getenv works

  • Accepts character vectors ('PATH') or string scalars ("PATH"). Both scalar forms return character vectors.
  • Vectorised calls are supported: pass a string array to receive a string array of values, or a cell array of character vectors to receive a cell array of character vectors.
  • When a scalar requested variable is not defined, getenv returns an empty character vector. Nonscalar string and cell containers retain their documented container type and dimensions.
  • Calling getenv with no arguments returns a dictionary whose keys and values are strings.
  • On Windows, environment variable lookups are case-insensitive, mirroring the operating system. On Unix-like systems, lookups are case-sensitive.
  • RunMat mode additionally accepts padded multirow character matrices and cells containing string scalars; both conveniences are independently disabled in MATLAB-compatible modes.
  • The builtin rejects non-text inputs, including every integer class and resident numeric handles, before provider access or environment lookup.

Does RunMat run getenv on the GPU?

getenv always runs on the CPU. No GPU kernels, downloads, or acceleration-provider hooks participate.

GPU memory and residency

No. getenv is a host environment query with textual inputs. Resident numeric values are invalid names and reject before provider access.

Examples

Read A Single Environment Variable

homeFolder = getenv("HOME");
disp(homeFolder)

Expected output:

homeFolder =
    "/"

Handle Missing Environment Variables

token = getenv("RUNMAT_TOKEN");
if token == ""
    warning("Token not configured.");
end

Expected output:

Warning: Token not configured.

Fetch Multiple Variables With A String Array

vars = getenv(["PATH", "SHELL"]);
disp(vars)

Expected output:

vars = 1x2 string
    "/usr/local/bin:/usr/bin:/bin"    "/bin/sh"

Use A Cell Array Of Character Vectors

cells = getenv({'HOME', 'PATH'});
disp(cells{1})

Expected output:

/

Inspect All Environment Variables

env = getenv();
disp(env("USER"))

Expected output:

"user"

Cache The Environment For Repeated Access

env = getenv();
resultsFolder = fullfile(env("HOME"), "results")

Expected output:

resultsFolder =
    "//results"

Using getenv with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how getenv changes the result.

Run a small getenv example, explain the result, then change one input and compare the output.

FAQ

What does getenv return when the variable is missing?⌄

A scalar character-vector or string-scalar query returns an empty character vector (''). You can test for a missing variable with isempty(value).

Does getenv support vectorised inputs?⌄

Yes. Pass a string array or a cell array of character vectors to retrieve multiple values in one call. The output mirrors the input container type.

Are environment variable lookups case-sensitive?⌄

RunMat follows the operating system. Lookups are case-insensitive on Windows and case-sensitive on Unix-like systems, matching MATLAB.

Does getenv modify the environment?⌄

No. It is a read-only operation. Use the forthcoming setenv builtin to modify the environment once it is available.

Can I call getenv from GPU-accelerated code?⌄

The environment lookup always executes on the host and accepts textual names. Resident numeric values are not converted into names and reject before provider access.

How do I access all environment variables at once?⌄

Call getenv() with no arguments. The result is a dictionary with string keys and values.

What happens if an environment variable name contains punctuation?⌄

The no-argument dictionary preserves the exact string key, so names do not need to be valid structure field identifiers.

Are trailing spaces in character inputs significant?⌄

No. Trailing spaces introduced by padding character matrices are stripped before the lookup so that MATLAB-style character arrays work as expected.

Does getenv include inherited environment variables?⌄

Yes. The builtin reports every variable visible to the RunMat process, including inherited values.

Related Io functions

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite

Net

accept · read · readline · tcpclient · tcpserver · write

Tabular

arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Filetext

fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines

Archive

gunzip · gzip · unzip

Hdf5

h5disp · h5info · h5read · h5write · h5writeatt · hdf5info · hdf5read · hdf5write

Import

importdata · textscan

Json

jsondecode · jsonencode

Mat

load · matfile · save

Http

sendmail · urldecode · urlencode · weboptions · webread · websave · webwrite

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how getenv is executed, line by line, in Rust.

  • View the source for getenv in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How getenv works
  • Does RunMat run getenv on the GPU?
  • GPU memory and residency
  • Examples
  • Read A Single Environment Variable
  • Handle Missing Environment Variables
  • Fetch Multiple Variables With A String Array
  • Use A Cell Array Of Character Vectors
  • Inspect All Environment Variables
  • Cache The Environment For Repeated Access
  • Using getenv with coding agents
  • FAQ
  • Related Io functions
  • Repl Fs
  • Net
  • Tabular
  • Audio
  • Io
  • Filetext
  • Archive
  • Hdf5
  • Import
  • Json
  • Mat
  • Http
  • Open-source implementation
  • About RunMat