# MX\_SETENV

> [HTML Version](mx_setenv.htm)

**xcall MIAMEX, MX\_SETENV, envdef \{,status\}**

MX\_SETENV (MIAMEX 56) is used to define environment variables for the current process, including the special case of TERM, for which see _Comments_, below. To set environment variables for the remote ATE client, see [Set Environment Variable](ag_setenv.md).

This function has both a [subroutine and a print tab implementation](subroutine-print-pairs.md).

**Parameters**

_envdef  _([String](string.md))  \[in\]

Contains a definition string of the form "name=value" specifying the name of the environment variable to be set (e.g. defined or modified) and its value. For example, "TERM=AM62CG", or "MYNAME=Jack". To delete an environment variable, set its value to nothing, e.g. "MYNAME=".

_status _(Signed [Num](num.md)) \[out\]

If specified, will return one of the following: 

| **Code** | **Meaningt** |
|------|------|
| 0 | Success |
| \-1 | General error |
| \-2 | Overflow of memory set aside for environment variables. |




**Comments**

In general, setting an environment variable doesn't have any immediate side effect. Instead the value is simply stored, for the purposes of retrieving it later, either using [MX\_GETENV](mx_getenv.md), or indirectly by referencing the variable name in some other expression context, as in the examples below:

xcall MIAMEX, MX\_SETENV, "MYPATH=c:\\vm\\miame\\jack", status

...

open #ch, "%MYPATH%\\myfile.log", output



In the example above, we use the %envvar% syntax, which is recognized by Windows as well as by A-Shell, regardless of the platform, in nearly all contexts where a filespec may be used. If specifying an environment variable in a Unix shell context, use the syntax \$env, e.g. \$MYPATH.

Environment variable definitions are available only to the current A-Shell prcess, and to those child processes launched by it (e.g. by [HOSTEX](hostex_sbr.md) or [MX\_SHELLEX](mx_shellex.md)). As an example of the former, under Unix:

xcall MIAMEX, MX\_SETENV, "MYPATH=/vm/miame/jack", status

...

xcall HOSTEX, "ls -l \$MYPATH/a\*", STDOUT\$



A-Shell itself defines and recognizes several environment variables.

The TERM environment variable, used by UNIX—and A-Shell—to indicate the type of terminal in use, is a special case. When set from within an A-Shell session connected to a remote terminal (e.g. a Telnet or SSH session), A-Shell also re-initializes its terminal configuration and possibly changes its internal terminal "driver" to match the terminal type.

For A-Shell/Unix, the TERM variable is typically established automatically when the Telnet/SSH session is initiated. But you may also set it manually prior to launching A-Shell (from the shell prompt), or you can set it via the -td command line switch.

**See Also**

•	[AG\_SETENV](ag_setenv.md)