In Spring, I know I can use the @Value annotation to read the value of a shell variable, e.g.,
public class MyClass {
@Value("${SHELL_VAR})
String shellVariable;
public String getShellVar() {
return shellVariable;
}
}
But then the value of SHELL_VAR is read only once from the shell. I want a way to read SHELL_VAR each time I call getShellVar(), since it changes over time.
3
It doesn’t matter what language or code you are using. In the common operating systems today like Windows, Linux, macOS, etc. when a process is launched it receives a copy of the environment variables it is going to use while executing. If you change the shell script that sets a variable and launches a program, it will affect the following executions, not the already running ones. Because of that it is not just possible to read updated values during execution. You may want to use a different method to send updated values to a running application, like configuration files, a database or some service that is queried by the application during execution time.