Fork me on GitHub
#planck
<
2016-11-02
>
honzabrecka13:11:45

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 “”}.

mfikes13:11:18

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

mfikes13:11:20

FWIW, Planck behaves like Clojure for this use case:

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

honzabrecka13:11:48

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

mfikes13:11:09

It essentially supports your exact use case, resulting in

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

honzabrecka13:11:27

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

mfikes13:11:05

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

mfikes13:11:52

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