planck

Planck ClojureScript REPL
2016-11-02T13:14:45.000389Z

Hi, how can I get value of an env variable? I tried (planck.shell/sh "echo" "$HOME”), but it returns {:exit 0, :out "$HOME\n", :err “”}.

mfikes 2016-11-02T13:17:18.000390Z

@honzabrecka One approach would be to parse the response of the env command.

mfikes 2016-11-02T13:19:20.000391Z

FWIW, Planck behaves like Clojure for this use case:

user=> (clojure.java.shell/sh "echo" "$HOME")
{:exit 0, :out "$HOME\n", :err “”}

2016-11-02T13:22:48.000392Z

@mfikes Thanks, I’ll go that way. In clojure we have System/getenv.

mfikes 2016-11-02T13:24:38.000393Z

@honzabrecka See parsing code here: https://github.com/mfikes/planck/issues/165#issuecomment-159069195

mfikes 2016-11-02T13:25:09.000396Z

It essentially supports your exact use case, resulting in

cljs.user=> (get (env.core/get-env) "HOME")
“/Users/mfikes”

2016-11-02T13:30:27.000398Z

Thanks. Just a note, it won’t work with variable that contains =, eg. some base64 encoded value.

mfikes 2016-11-02T13:48:05.000399Z

@honzabrecka Thanks! I fixed the example parsing code there for that issue.

mfikes 2016-11-02T13:48:52.000400Z

I added a 2 to (string/split line #"=" 2)