Fork me on GitHub
#babashka
<
2021-12-13
>
sheluchin21:12:06

Is there a way to set env vars for tasks? I saw https://github.com/babashka/babashka/issues/849, so guessing not, but maybe there's a workaround?

borkdude21:12:05

@alex.sheluchin you can set env vars for shell and clojure, both with (f {:extra-env {"FOO" "BAR"}} ...)

sheluchin21:12:37

@U04V15CAJ what am I doing wrong here?

foo (shell {:extra-env {:FOO "BAR"}}
           "echo $FOO")             
$ bb foo
$FOO
I tried with both "FOO" and :FOO and got the same result, like it's not performing the expansion. I tried the keyword version because of this example in the bb/process readme:
user=> (-> (process '[sh -c "echo $FOO"] {:env {:FOO "BAR"}}) :out slurp)
"BAR\n"

borkdude21:12:50

echo $FOO
is bash syntax.

sheluchin21:12:13

Ah, okay, I was confused in thinking bash syntax is okay there. Either "printenv FOO" or pass the command to the shell with -c. I'm not familiar with Runtime.exec() - didn't quite understand its execution context. Thanks @U04V15CAJ.

borkdude21:12:17

This uses ProcessBuilder, not Runtime.exec, but it's similar. There is nothing bash specific in this since it works cross platform

sheluchin22:12:25

That makes sense seeing as clojure and shell both return a bb/process, which is a wrapper for ProcessBuilder. I think it's a little unclear because shell returns a process, and process has sh, but not shell, but there's also clojure.java.shell which has a sh and they all kinda perform.. just about the same thing, but not quite. There's a lot of name overloading going on, which I suppose is intentional to make things familiar, but still makes my brain 🤯 a little 🙂 Just my impression as someone fairly new to this machinery. I don't know if the docs could clarify this for a newbie like me. But for what it's worth, I did search for "environment variable" and similar terms in the book and couldn't find what I was looking for. Maybe it's common enough of an operation that it should get a ctrl+f friendly mention? Thanks for the help @U04V15CAJ. Just wanted to provide some feedback. Appreciate your work 🙏

borkdude22:12:25

@alex.sheluchin Yes, you are absolutely right and this is on my TODO list, but feel free to make a PR to the book if you want to have it in there sooner :)

👍 1
borkdude22:12:12

Thank you for sponsoring!

sheluchin23:08:12

@U011NGC5FFY do you mean documentation on setting env vars? I think I added a blurb when this came up. https://github.com/babashka/book/commit/28e24277ec6c5ecaaec01abe3b644433b7cd06cb Does that cover it?

Eugen23:08:38

no, on the fact that shell is not a bash shell - so it does not do expansion + example on how to do expansion.

sheluchin00:08:42

Babashka is open to pull requests from the community if you're feeling up to it.

👍 1
borkdude09:08:46

If you think docs should be improved, please create PRs and/or issues

Eugen10:08:17

yeah thanks. I learned to ask first. Not all my ideas are great.Neither all people open to accept them, good or not.

👍 1