We have a Java Spring Boot based program which reads the following line from a property file:
spring.cloud.config.username=${USER:root}
When it runs on Linux server, it’s able to retrieve the current user name based on ${USER:root}.
When I do “echo ${USER:root}” on the Linux bash command prompt, I am also able to see the current user name printed out.
Question 1:
But what does ${USER:root} actually mean? When I do “echo ${USER:r}”, with an incomplete “root”, it will also print out the current user name.
However, when I do “env” at the command prompt, I don’t see USER:root in the result, but I can see USER printed with the value of the current user name.
I am trying to write a small Java program, non Spring Boot based, that will read from the same line of the same property file above. The Java program should be able to retrieve the actual value from ${USER:root}. Using System.getEnv(), I am able to retrieve all the environment variables on the Linux server, but somehow only USER is found from System.getEnv() result, but not USER:root.
Question 2:
How can I get the value of ${USER:root} using Java?