Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an environment variable from within the sbt shell

I would like to be able to set an environment variable from within the interactive sbt shell, and I can't seem to find a way to do that. (I have looked on the official sbt docs as well as on stackoverflow without success).

I want to make it clear that I don't want to have to set this environment variable in the build.sbt file, but rather be able to change it on the fly on my interactive sbt shell session, so that the environment variable is used for the next sbt commands I run.

For example, I would like to be able to do something like (from within the sbt shell):

> set_environment_variable("foo", "foo_value")
> `mymodule`/run
> (... program runs and completes)
> set_environment_variable("foo", "another_foo_value")
> `mymodule`/run

Is this possible? And if it is, how can I do it?

like image 821
Thundzz Avatar asked Jan 18 '18 17:01

Thundzz


People also ask

How do I set an environment variable in Shell?

You can set your own variables at the command line per session, or make them permanent by placing them into the ~/. bashrc file, ~/. profile , or whichever startup file you use for your default shell. On the command line, enter your environment variable and its value as you did earlier when changing the PATH variable.

How do I reference an environment variable from the command line?

To reference a variable in Windows, use %varname% (with prefix and suffix of '%' ). For example, you can use the echo command to print the value of a variable in the form " echo %varname% ".

How do I pass an environment variable in Intellij?

From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog, select a configuration you want to add the environment variables to. Type the variable name and value: <name>=<value> .


1 Answers

Using sbt 0.13.15 the only thing I've found which has worked for me is to use eval.

> eval System.setProperty("foo", "foo_value")
> `mymodule`/run
> ...
> eval System.setProperty("foo", "another_foo_value")
> `mymodule`/run
like image 138
Shane Perry Avatar answered Sep 17 '22 15:09

Shane Perry