I am trying to System.getenv()
to get the value of an environment variable that I have set through my terminal (Mac), I also set the variable in my .bash_profile file and reloaded. After doing so, I echo'd the value and the correct value was printed to the terminal. When trying to retrieve the value of the variable (I made sure I was using the correct name in both my .bash_profile file and when using System.getenv()
.
In the below code, I have replaced the name of the variable with VAR_NAME:
String varValue = System.getenv("VAR_NAME");
System.out.println("Value: " + varValue);
In my .bash_profile:
export VAR_NAME="foo"
"null" is printed when I print out the value of varValue
.
What could be the cause of this?
Edit: I followed the top answer here, restarted Eclipse and it worked!