Function | Package: system | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 9.0 Unrevised from 8.2 to 9.0. 8.2 version

## getenv

Arguments: string

The new `:osi` module, released after the release of Allegro CL 6.2, has additional functionality relating to environment variables, including setenv and unsetenv. See OSI miscellaneous low-level functionality in os-interface.htm. The symbol `system:getenv` is exported from the new `excl.osi` package (as well as from the `system` package).

This function returns the value (a string) of an environment variable (such as TERM, SHELL, and DISPLAY). If the environment variable is not defined, nil is returned. This function may be used with setf to set an environment variable. For example:

    ;; The current values of the environment variable on your system may,
    ;; of course, be different from what appears in this example.
    user(2): (sys:getenv "SHELL")
    "/bin/csh"
    user(3): (setf (sys:getenv "SHELL") "/bin/sh")
    "/bin/sh"
    user(4): (sys:getenv "SHELL")
    "/bin/sh"

Warning: When you use setf with sys:getenv to set an environment variable, the string specifying the new value is stored in malloc'ed space and that space cannot be freed (in any practical way). This creates a small memory leak in the system, but it should only be significant if you set many, many environment variables.

Note that there is no pre-defined, programmatic way to unset an environment variable from within Lisp. It is an error to setf sys:getenv to anything other than a string and the effect of doing so is undefined (an error is typically not signaled but the behavior is likely not what is intended). Specifically.

    (setf (sys:getenv "VAR") nil)

does not unset VAR in the environment.

See os-interface.htm.

Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 8.2 page.
Created 2012.5.30.

|  | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 9.0 Unrevised from 8.2 to 9.0. 8.2 version