2

I try to execute echo ${GOPATH} with call-process as below:

(call-process "echo" nil t nil "${GOPATH}")

But it only output "${GOPATH}" not the value of that value. Would anyone please let me know what the correct way to do it?

1 Answer 1

5

You're looking for (call-process-shell-command "echo ${GOPATH}" nil t nil). In this case, ${PATH} is syntax defined by a shell, not a native call, so you'll need to invoke a shell to interpret it.

However, you may be interested in (insert (getenv "GOPATH")) which is considerably more direct, as it simply reads the environment instead of spawning a shell to read the environment in its stead.

2
  • 1
    Good answer, but note that the environment Emacs sees is not necessarily the environment that your shell sees (generally depending on how and where Emacs is invoked).
    – phils
    May 13, 2016 at 5:09
  • @phils ah. Thanks for reminding me. I always spawn Emacs from a shell, so I forget.
    – PythonNut
    May 13, 2016 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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