0

I set my variable like this:

SET Ant="%HOMEDRIVE%%HOMEPATH%\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin"

:: Set Path variable  
setx PATH "%Ant%" /m

Then, the result for the path variable is :

C:\Users\Ruben\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin

As we can see, environnement variables are expanded.

I would like them not to be expanded to set my path variable like this:

%HOMEDRIVE%%HOMEPATH%\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin

Is there a way to not expand environnement variables ?

krisFR
  • 13,280
  • 4
  • 36
  • 42
Ruben
  • 111
  • 4

1 Answers1

2

This do the trick on my Win7 :

SET Ant=^%HOMEDRIVE^%^%HOMEPATH^%\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin

setx PATH "%Ant%" /m

Let's check if everything is ok :

echo %Ant%
%HOMEDRIVE%%HOMEPATH%\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin

set | findstr Ant
Ant=%HOMEDRIVE%%HOMEPATH%\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin

Everything seems ok :)

To makes it work i had to :

  • Escape % characters using carets (^).
  • Remove double quotes.
krisFR
  • 13,280
  • 4
  • 36
  • 42