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:
- If the IDL_TMPDIR preference has a non-NULL value, GETENV returns the value of that preference. For more information on this preference, see IDL_TMPDIR.
- On UNIX systems, IDL uses the value of the standard TMPDIR environment variable. If TMPDIR is not defined, IDL chooses a reasonable temporary directory based on operating system and vendor conventions.
- On Windows systems, IDL uses the value provided by Windows, which is the first of the following that is defined: the value of the TMP environment variable, the value of the TEMP environment variable, or the default value for the current Windows version.
This special processing has the following benefits:
- IDL_TMPDIR always yields a temporary directory path, so IDL code can use it immediately without additional work.
- The default behavior is to use the system defined location for temporary files, meaning that IDL applications automatically follow the standard conventions of the underlying platform.
- Sometimes, local site considerations require the use of a non-standard location. The IDL_TMPDIR preference lets this requirement be managed in an easy and flexible manner.
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
Version History
Original |
Introduced |
6.1 |
ENVIRONMENT keyword modified to work on all platforms |