1

I was trying to access environment variables in an Eclipse Scala Worksheet and it wouldn't work.

Initially it was because my variable was defined in .bashrc and that is not good, since .bashrc is only for login shells and not GUI applications. I changed the variables to .profile, sourced the file and reloaded my session (logging out and logging in, just in case). After that I could access the variables in a normal Scala script (in Eclipse) but still couldn't in the worksheet. Any ideas?

Thanks!

UPDATE:

testworksheet.sc

object testworksheet {
    val key = sys.env("my_key")
    // Result in a NoSuchElementException in the worksheet,
    // though works in a script.
}

~/.profile

export my_key=my_value
marcelocra
  • 2,094
  • 2
  • 24
  • 37
  • 1
    To increase the chance of getting a relevant answer, please consider providing an appropriate example code. See http://stackoverflow.com/help/mcve. – Fernando Correia Jul 02 '14 at 21:34
  • Updated the question, though there is not much to it since I believe it is more of a configuration problem. Thanks anyway. – marcelocra Jul 02 '14 at 22:18

1 Answers1

0

The .profile is also for setting up variables for your interactive shell, which passes those variables along to a script since this shell is what you run the script from.

If you want to pass variables to eclipse you have to make them system-wide, i.e. to put them in /etc/environment or /etc/profile.d. See some doc here.

In a completely different approach, you can also set application-specific variables for your application.

Community
  • 1
  • 1
Francois G
  • 11,957
  • 54
  • 59