Why gives the following Windows 7 .cmd command script:
set SUN_JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_17
if 3==3 (
set JAVA_HOME=%SUN_JAVA_HOME%
)
echo ready
The following error message instead of printing “ready”
\Java\jdk1.6.0_17 was unexpected at this time.
The error message disapears, if I remove the “(x86)” in the path name.
The problem is the parentheses grouping after the
if 3==3part.While parsing the
set JAVA_HOME=%SUN_JAVA_HOME%command, the interpreter immediately replaces the%SUN_JAVA_HOME%variable and that causes an early match of the closing parenthesis in(386).This can be avoided if you enable delayed expansion and replace
%SUN_JAVA_HOME%with!SUN_JAVA_HOME!: