2

I'm trying to use a command that uses environment variables, and following is working fine( this is not the actual command I'm going to use).

Seq("echo "+System.getenv("JAVA_HOME"))! 

but is there way to use the following kind of syntax ? In the case if we load the command from .sh file ?

Seq("echo ${JAVA_HOME}")!

1 Answer 1

3

You can use scala process with bash -c to get environment variables:

import scala.sys.process._
val value = Seq("bash", "-c", "echo $JAVA_HOME").lines.head
Sign up to request clarification or add additional context in comments.

1 Comment

@chengphi yes , I'm want to access environment variables as we use in standard scripts instead of using System.getenv

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.