Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to Elisp. I would like to do the following in my init file:

; Retrieve the value of LD_LIBRARY_PATH
; Append '/path/to/some/lib/:'to it
; Save the new value of LD_LIBRARY_PATH

So far I know that I can use:

(getenv "LD_LIBRARY_PATH")

to retrieve the value, and:

(setenv "LD_LIBRARY_PATH" "foo")

to set a new value, but my knowledge of Elisp is extremely rudimentary so I don't know to proceed from this point.


This question is inspired by the fact that it is not be possible to source a shell script to manipulate this environment from within Emacs, so I would need to do this using Elisp.

share|improve this question
up vote 4 down vote accepted

In Elisp, string concatenation is done with concat:

  (let ((current (getenv "LD_LIBRARY_PATH"))
        (new "/path/to/some/lib"))
    (if current (concat new ":" current) new)))
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.