GETENV

The GETENV function returns the value of one or more specified environment variables from the environment of the IDL process.

About the Process Environment

Every process has an environment consisting of environment variables, each of which has an associated string value. Some environment variables always exist, such as PATH, which tells the shell where to look for programs. Others can be added by the user, either interactively via a shell, via a UNIX startup file such as .login, or a via a Windows control panel.

When a process is created, it is given a copy of the environment from its parent process. IDL is no exception to this; when started, it inherits a copy of the environment of its parent process, which may be an interactive shell, the windowing system’s desktop environment, or some other process. In turn, any child process created by IDL (such as those from the SPAWN procedure) inherits a copy of IDL’s current environment.

Note: It is important to realize that environment variables are not an IDL feature; they are part of every process. Although they can serve as a form of global memory, it is best to avoid using them in that way. Instead, IDL heap variables (pointers or object references), IDL system variables, or common blocks should be used in that role. Environment variables should be used for communicating with child processes. One example is setting the value of the SHELL environment variable prior to calling SPAWN to change the shell executed by SPAWN.

Examples

To print the name of the current UNIX shell, enter the command:

PRINT, 'The current shell is: ', GETENV('SHELL')

To store the path to the directory where IDL believes temporary files should be placed in the variable mytemp, use the following statement:

mytemp = GETENV('IDL_TMPDIR')

Syntax

Result = GETENV( Name [, /ENVIRONMENT] )

Return Value

Returns the value of the environment variable Name from the environment of the IDL process, or an empty string if Name does not exist in the environment. If Name is an array, the result has the same structure, with each element containing the value for the corresponding element of Name.

Arguments

Name

A scalar string or string array variable containing the names of environment variables for which values are desired.

Note: Under UNIX, environment variable names are case sensitive. Under Windows, case is ignored, with one exception: because it is handled specially, the IDL_TMPDIR environment variable should always be specified in upper case characters.

Special Handling of the IDL_TMPDIR Environment Variable

The normal action of GETENV is to look up the specified name in the environment without performing any special action, and to return an empty string if it is not found. However, if you specify the upper-case string “IDL_TMPDIR” as the value of Name, GETENV takes the following special actions:

This special processing has the following benefits:

Keywords

ENVIRONMENT

Set this keyword to return a string array containing all entries in the current process, one variable per entry, in the SETENV format (Variable=Value). If ENVIRONMENT is set, the Name argument should not be supplied.

See Also

SETENV

Version History

Original

Introduced

6.1

ENVIRONMENT keyword modified to work on all platforms