0

When JAVA_HOME is not set, then echo command will display the command instructions as it is:

C:\>echo %JAVA_HOME%
%JAVA_HOME%

To set the user environment variables, used setx command to do it.

setx JAVA_HOME "C:\jdk-8u172"
SUCCESS: Specified value was saved.

C:\>echo %JAVA_HOME%    
%JAVA_HOME%

How to display the user environment variable details on the command line?

But when the JAVA_HOME is added with set command, then echo command displayed the path added in JAVA_HOME variable:

C:\>set JAVA_HOME="C:\jdk-8u172"
C:\>echo %JAVA_HOME%
"C:\jdk-8u172"

C:\Users\raju>

How echo command is restricted to display user environement variable details?

xxxvodnikxxx
  • 1,270
  • 2
  • 18
  • 37
Vivaswan
  • 337
  • 4
  • 17
  • If you set the value from command prompt then that value will be their only for that session. Once you close the command prompt the scope variable is lost. So if you are using unix then set the value in bashprofile file – Prasad Apr 19 '18 at 11:08
  • @PrasadReddy answer submitted by xxxvodnikxxx. In new command prompt or new shell command, echo displayed the JAVA_HOME and PATH added using setx. – Vivaswan Apr 19 '18 at 11:32

1 Answers1

1

from superuser post

SETX is for user variables.

SET is for shell variables.

It means...

  • When you use set command, then its used for the current shell session only
  • When you use setx command, then its persistent, but to take effect, you need to open new shell otherwise it will be looking like its still not set- reopening new session will reload variables.
Community
  • 1
  • 1
xxxvodnikxxx
  • 1,270
  • 2
  • 18
  • 37
  • But the question remains same, why "echo" command output won't reflect in the same shell command session? – Vivaswan Apr 19 '18 at 11:40
  • Its the thing of OS, If you will be making editation of some text file, then until you save it, you can reopen it many times in different editors, but the content will be still the same. This is basically the same.. – xxxvodnikxxx Apr 19 '18 at 11:43
  • So the environment variables are being loaded definitely when the shell starts, only approach can be to find some command to reload them "on-fly" but i havent found any for windows, on Linux it seems it can be done by reload user profile file `source ~/.bashrc` – xxxvodnikxxx Apr 19 '18 at 12:38