In Java, reading environment variables is done with System.getenv().
System.getenv()
Is there a way to do this in Scala?
Using directly a default with getOrElse over the sys.env Map (val myenv: Map[String, String] = sys.env):
getOrElse
sys.env
val myenv: Map[String, String] = sys.env
sys.env.getOrElse(envVariable, defaultValue)
You get the content of the envVariable or, if it does not exist, the defaultValue.
envVariable
defaultValue