( was unexpected at this time.

Microsoft Windows home server 2011 32-bi...
August 5, 2011 at 11:01:40
Specs: Windows 7
I am currently writting a batch script that will your parameters and change your ip, subnet mask, default gateway, and 2 DNS servers based on the parameters. You need either 3 OR 5 parameters in order for it to work. I just started like half an hour ago, but i am stuck and idk what is going. No matter what i put for the parameters, after it announces them, i get a "( was unexpected at this time." What is wrong?


@echo off
cls
if "%1" == [] (
echo No Argument for 1
set one=no
) ELSE (
echo The Argument for 1 is %1
)

if "%2" == [] (
echo No Argument for 2
set two=no
) ELSE (
echo The Argument for 2 is %2
)

if "%3" == [] (
echo No Argument for 3
set three=no
) ELSE (
echo The Argument for 3 is %3
)

if "%4" == [] (
echo No Argument for 4
set four=no
) ELSE (
echo The Argument for 4 is %4
)

if "%5" == [] (
echo No Argument for 5
set five=no
) ELSE (
echo The Argument for 5 is %5
)

pause


IF %one% == no ( GOTO :err)

IF %two% == no ( GOTO :err)

IF %three% == no ( GOTO :err)

IF %four% == no ( GOTO :cont3)

IF %five% == no ( GOTO :err)

:ERR
echo One or more parameters missing
pause
goto :end

:CONT3
echo 3 parameters specified
pause
goto :end

:END
cls


See More: ( was unexpected at this time.

Report •


#1
August 5, 2011 at 11:25:15
@echo off
This line: Remove it. Then run your script, and give us the output.

How To Ask Questions The Smart Way


Report •

#2
August 5, 2011 at 12:08:23
kk, i am trying it with different combinations of parameters (forgot to mention, its better if you start this from the command line)


Last few lines:

C:\Users\myname\Documents\Changing Subnet Mask IP and Gateway>pause
Press any key to continue . . .
( was unexpected at this time.
C:\Users\myname\Documents\Changing Subnet Mask IP and Gateway>IF == no
( GOTO :err)
C:\Users\myname\Documents\Changing Subnet Mask IP and Gateway>


Report •

#3
August 5, 2011 at 13:22:21
IF == no
What we learn from this: A blank variable is expanded as an empty string.
Workaround: Enclose parameters on both sides in double quotes.
Example:
IF "%one%"=="no" GOTO :err

How to dramatically cut down on the busy work line count:
Test to see if the fifth parameter is there. If it is, then 1 though 4 must be there as well.

@echo off
cls
IF "%5"=="" GOTO :err

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
August 9, 2011 at 22:21:14
Ok, i have no idea what i did, but i guess i managed to fix it :P Thanks anyway!!

Report •


Ask Question