我想检查环境中是否存在JAVA_HOME
所以我写了下面的脚本a.bat
if "%JAVA_HOME%" == ""
(
echo Enter path to JAVA_HOME:
set /p javahome=
)
if not "%JAVA_HOME%" == ""
(
echo %JAVA_HOME%
)
它显示“命令的语法不正确”我哪里出错?
答案 0 :(得分:19)
试试这个:
@echo off
IF "%JAVA_HOME%" == "" (
echo Enter path to JAVA_HOME:
set /p JAVA_HOME=
) ELSE (
echo %JAVA_HOME%
)
答案 1 :(得分:2)
if not defined JAVA_HOME (
:undefined
set /p JAVA_HOME=Enter path to JAVA_HOME:
if not defined JAVA_HOME goto:undefined
)
echo %JAVA_HOME%