2

From within my Scala application, I want to execute a script (e.g. setenv.sh) which sets some variables. I then want to read back these variables in my application to do some further processing. Here is my sample setenv.sh file

#!/bin/bash

TEST=0000

I have the following but it doesn't work. I tried many alternatives but failed to do it.

Seq("bash", "-c", "source setenv.sh && env").!!

The above command still gives me the old environment variables and i cannot see TEST.

My goal is to just load all the variables in setenv.sh file and use them in my application.

1
  • I appreciate the quick comeback! Commented Aug 5, 2018 at 5:11

1 Answer 1

1

Can't work that easy. Keep in mind that you are opening a new shell process. That process sees the setting - to then end.

If at all try explicitly exporting that value.

Alternatively you could print the values to stdout and have Scala parse that output.

Sign up to request clarification or add additional context in comments.

2 Comments

I am currently looking for a solution without any modifications to setenv.sh script. Is it possible to execute the setenv.sh and then somehow get the environment variables of the new process in the parent process?
Again: currently your script isn't doing something that has any effect on the parent process. Unless you change the script, you are broken.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.