Skip to content

Environment and shell

Brett Estrade edited this page Nov 18, 2026 · 3 revisions

Environment and shell commands

%ENV is the live environment of the AnteREPL process. Changes are visible to Perl and to child commands started afterward.

Inspect and change a variable

ENV
ENV PATH
ENV SET GREETING 'hello world'
ENV GREETING
ENV UNSET GREETING

ENV displays sorted VAR=value lines. Quotes preserve values containing spaces. ENV SET NAME "" sets an empty value; ENV UNSET NAME removes it.

Normal Perl works too:

$ENV{GREETING} = 'hello world';
say $ENV{GREETING};
DUMP \%ENV
delete $ENV{GREETING};

ENV subcommand names are reserved: use DUMP $ENV{SET} to inspect a variable whose name is SET, for example.

Edit the environment in your editor

EDIT ENV

ENV EDIT is an alias. The editor receives a private temporary environment.env containing lines such as:

EDITOR=vim
GREETING="hello world"
LITERAL='$HOME stays literal'

Save and close the editor to replace the live environment. Removing a line unsets that variable; an empty file clears the environment. Invalid syntax, duplicate names, or an unsuccessful editor exit leaves the current environment intact. Program source and its UNDO history are separate.

The format is familiar VAR=value, but the file is data, not a shell script:

Form Interpretation
NAME=value Outer whitespace trimmed
NAME=' literal value ' Exact text between single quotes
NAME="line one\nline two" Double quotes decode supported escapes
NAME=value # note A whitespace-preceded hash starts a comment
NAME=abc#def Hash remains part of the value
export NAME=value Optional export prefix accepted
Blank line or # comment Ignored

Double quotes support \n, \r, \t, \\, \", and \xHH. UTF-8 text is supported; non-UTF-8 bytes are represented with hex escapes. Names cannot contain whitespace, =, #, quotes, or NUL; values cannot contain NUL. Dollar signs, backticks, and command substitutions are never evaluated. Single quotes are convenient for literal Windows paths containing backslashes.

Save and reload a working environment

Try this sequence:

ENV SET EXAMPLE_COLOR blue
ENV SAVE session.env
ENV SET EXAMPLE_COLOR red
ENV RELOAD
ENV EXAMPLE_COLOR

The final result is EXAMPLE_COLOR=blue. RELOAD re-reads the last successfully saved or loaded environment file. You can supply a filename explicitly:

ENV LOAD other-session.env
ENV RELOAD other-session.env

LOAD and RELOAD replace the whole environment, rather than merging a few entries. EDIT ENV updates memory only; ENV SAVE file writes it to disk. ENV RESET restores the environment inherited at startup. Plain RESET affects the Perl workspace and leaves %ENV alone.

Use the shell explicitly

Prefix shell commands with !:

! pwd
! env
! cat filename

The available commands and expansion syntax are those of your system shell. On Unix AnteREPL uses /bin/sh; native Windows uses COMSPEC or cmd.exe. For example, a Unix shell command sees a variable set above:

ENV SET GREETING 'hello world'
! printf '%s\n' "$GREETING"

In screen mode, ! captures stdout/stderr and displays them when the command finishes; stdin is closed. For an interactive application, use !!:

!! perl -de 0

It receives the real terminal. When it ends, press Enter to return to the AnteREPL screen. In plain mode both escapes use normal terminal I/O.

Directory and parent-shell behavior

Use CD or its alias CHDIR to change the session's directory:

CD ..
CHDIR '/path/to/work'
CD 'directory with spaces'

Paths are literal, with quoting for spaces. With no argument, these commands use HOME, or USERPROFILE on native Windows when HOME is unset. A failed change prints an explanation and leaves the working directory unchanged. There is no shell expansion of $variables or ~ in these command arguments.

Lowercase chdir is still ordinary Perl. Use it for Perl expressions and your own error handling:

chdir '/path/to/work' or die $!;
chdir $ENV{HOME} or die $!;

! cd ... changes only the short-lived child shell. Likewise, exporting a variable in a ! command cannot change AnteREPL's environment. Use %ENV or ENV SET for persistent changes in the session.

AnteREPL cannot modify its parent shell or retrieve changes made there after startup. To transfer later settings, write a compatible file and use ENV LOAD.

Clone this wiki locally