Reputation: 41
I am trying to get escape character like below:
C:\\Program Files (x86)\\Java\\jdk1.7.0_25
Here is the code in batch script:
set AGNT_JAVA_HOME=%JAVA_HOME% SET
set AGNT_JAVA_HOME=%AGNT_JAVA_HOME:\\=\\\\%
But the value coming is :
AGNT_JAVA_HOME value is C:\Program Files (x86)\Java\jdk1.7.0_25
Any idea what need to be added here to get the value as first line.
Upvotes: 1
Views: 169
Reputation: 130919
The escape character for batch is ^
, not \
.
The \
literal does not require escaping.
So all you need is:
set AGNT_JAVA_HOME=%AGNT_JAVA_HOME:\=\\%
But it is safer to enclose the entire SET assignment in quotes, just in case AGNT_JAVA_HOME contains a poison character like &
.
set "AGNT_JAVA_HOME=%AGNT_JAVA_HOME:\=\\%"
Upvotes: 2