1

Here is how I try to update an evironment variable JAVA_HOME

if "%JAVA_HOME%" == "" (
    where java > java_path
    echo File contents is
    type java_path
    set /p JAVA_HOME=< java_path
    echo %JAVA_HOME:~0,-13%
    set JAVA_HOME=%JAVA_HOME:~0,-13%
)

The output I get is

File contents is
C:\Program Files (x86)\Java\jre7\bin\java.exe
~0,-13

I am getting weird ~0,-13 instead of C:\Program Files (x86)\Java\jre7 which is expected because where java is C:\Program Files (x86)\Java\jre7\bin\java.exe

Curiously, it succeeds if I remove if "%JAVA_HOME%" = "" condition.

Little Alien
  • 1
  • 8
  • 22
  • 2
    you need [delayed expansion](http://stackoverflow.com/a/30284028/2152082): `echo !JAVA_HOME:~0,-13!` and `setlocal enabledelayedexpansion` at the start of your script. – Stephan Jun 21 '16 at 17:12

0 Answers0