[ Operating System | Reference Manual | Alphabetic Index ]

getenv(+Name, -Value)

Succeeds if Name is the name of an environment variable or registry entry, and returns the corresponding value.
Name
String or atom.
Value
String or variable.

Description

The first argument must be a string or an atom. The predicate looks up a value which the operating system has stored under this key.

UNIX: If Name is the name of a UNIX environment variable, this variable's value is returned. As an additional feature, if there exists an environment variable whose name is the concatenation of the value of Name and the ECLiPSe version number (e.g. "ECLIPSEDIR_4_9" if Name is "ECLIPSEDIR" and the version is 4.9), then this variable's value is returned instead.

WINDOWS: The name Name is looked up in the registry under the key HKEY_LOCAL_MACHINE\SOFTWARE\IC-Parc\ECLiPSe\<version>. If there is such an entry, its value is returned. Otherwise, Name is taken as the name of an environment variable, whose value is returned if it exists.

If the lookup operation is unsuccessful, the predicate fails.

Modes and Determinism

Fail Conditions

Fails if none of the lookup methods yielded any result for the given name

Exceptions

(4) instantiation fault
Name is not instantiated.
(5) type error
Name is instantiated, but not to a string or an atom.
(5) type error
Value is instantiated, but not to a string.

Examples

Success:
      getenv('HOME',V).    (gives V="/home/username").
      getenv("SHELL",V).   (gives V="/bin/csh").
      getenv('TERM',V).    (gives V="sun-cmd").
      getenv('USER',V).    (gives V="username").

Fail:
      getenv('HOEM',V).

Error:
      getenv(TERM,V).               (Error 4).
      getenv('TERM',atom).          (Error 5).
      getenv(1,V).                  (Error 5).



See Also

setenv / 2, sh / 1, argv / 2, argc / 1