: was unexpected at this time
I am creating a bat file that does some basic functions for server builds. The script is made to be somewhat interactive. This allows us to use on script for Production, Dev, or QA. The area of the script that fails is below
echo Enter User-defi开发者_StackOverflow中文版ned Information about this Server:
echo Environment:
echo 1. PROD
echo 2. QA
echo 3. Dev
echo Choose one:
CHOICE /C 123
if errorlevel 1 (set ENVIRONMENTNAME=PROD & set ENVNAME=Production)
if errorlevel 2 (set ENVIRONMENTNAME=QA & set ENVNAME=Acceptance)
if errorlevel 3 (set ENVIRONMENTNAME=Dev & set ENVNAME=Development)
Once I am prompted to "Choose One:" I choose either of the options then get the error:
: was unexpected at this time.Remove the @echo off
or echo off
commands from the top of the script (or add echo on
), and use the resulting output to debug which line causes the offending error.
For optimization purposes, put your if errorlevel
commands in descending order. The if errorlevel
command triggers when the ERRORLEVEL
is the specified number or higher.
I realise this is a rather belated answer, but I've just experienced exactly the same error message, although it was a "set /p" that was causing the problem for me. The line was originally:
set /p Option=Do you want to go ahead and load the data? ([Y]/N):
and the solution I found was to put double quotes around the prompt text, so:
set /p Option="Do you want to go ahead and load the data? ([Y]/N): "
Don't know if that will help anyone or not, but it solved the problem for me :-)
精彩评论