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?

Drew
  • 75,699
  • 9
  • 109
  • 225
Enze Chi
  • 1,410
  • 12
  • 28

1 Answers1

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.

PythonNut
  • 10,243
  • 2
  • 29
  • 75
  • 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 '16 at 05:09
  • @phils ah. Thanks for reminding me. I always spawn Emacs from a shell, so I forget. – PythonNut May 13 '16 at 05:11