Function: getenv

getenv is an interactive and byte-compiled function defined in env.el.gz.

Signature

(getenv VARIABLE &optional FRAME)

Documentation

Get the value of environment variable VARIABLE.

VARIABLE should be a string. Value is nil if VARIABLE is undefined in the environment. Otherwise, value is a string.

If optional parameter FRAME is non-nil, then it should be a frame. This function will look up VARIABLE in its environment parameter.

Otherwise, this function searches process-environment for VARIABLE. If it is not found there, then it continues the search in the environment list of the selected frame.

View in manual

Probably introduced at or before Emacs version 21.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/env.el.gz
(defun getenv (variable &optional frame)
  "Get the value of environment variable VARIABLE.
VARIABLE should be a string.  Value is nil if VARIABLE is undefined in
the environment.  Otherwise, value is a string.

If optional parameter FRAME is non-nil, then it should be a
frame.  This function will look up VARIABLE in its `environment'
parameter.

Otherwise, this function searches `process-environment' for
VARIABLE.  If it is not found there, then it continues the search
in the environment list of the selected frame."
  (declare (ftype (function (string &optional frame) (or null string)))
           (side-effect-free t))
  (interactive (list (read-envvar-name "Get environment variable: " t)))
  (let ((value (getenv-internal (if (multibyte-string-p variable)
				    (encode-coding-string
				     variable locale-coding-system)
				  variable)
				(and frame
				     (assq 'environment
					   (frame-parameters frame))))))
    (if (and enable-multibyte-characters value)
	(setq value (decode-coding-string value locale-coding-system)))
    (when (called-interactively-p 'interactive)
      (message "%s" (if value value "Not set")))
    value))