Goto was unexpected time - batch-file

When I run the script Console prints goto was unexpected time, (I have bad English)
#echo on
set versiyon=0.1
if %komut1%=="metin" goto metinapi
if %komut1%=="internet" goto internetapi
if %komut1%=="dosya" goto dosyaapi
if %komut1%=="sistem" goto sistem
if %komut1%=="versiyon"(
echo %versiyon%
pause
)
color c
echo Hata:Aranan sey bulunamadi!Aradiginiz seyi dogru yazdiginizdan emin
olun!ya da frameworku guncelleyin. suanki verisyon:%versiyon% KOD:1
pause
:metinapi
if %komut2%=="degistir"(
if %komut3%=="" goto null
if %komut4%=="" goto null
if %komut5%=="" goto null
setlocal ENABLEDELAYEDEXPANSION
set str=%komut3%
set str=%str:!komut5!=!komut4!%
echo %str%
pause
)
if %komut2%=="bul"(
if %komut3%=="" goto null
if %komut4%=="" goto null
Echo.%komut3%| findstr /C:%komut4%>nul && (Echo.EVET) || (Echo.HAYIR)
pause
)
:null
color c
echo Deger null olamaz!KOD:2
pause
You can say why komuts are empty beacause I want user input them like api.bat set komut1=metin set komut2=bul ...

You haven't declared %komut1%, and therefore the if command failed as well. And if the command if executed (right at the line #3), then it would be:
if =="metin" goto metinapi
^
Error here, because "%komut1%" is equal to ""
To fix this, you may have to include double quotes " before and after %komut1%:
if "%komut1"=="metin" goto metinapi
Now not only that, but you may have to edit more commands in order to make it working, like after you fix line #3, you'll have to fix line #4 and #5, etc...

Related

Batch file, If Statement not working

The following if statement is not running. It just ends the bat file It stops the process. Why is this happening? How do I stop it?
if "%Choice%"=="si" (GOTO Case2) else (
if "%Choice%"=="s" (GOTO Case1) else (
if "%Choice%"=="ti" (GOTO Case4) else (
if "%Choice%"=="t" (GOTO Case3) else (
if "%Choice%"=="i" (GOTO Case5) else (
if "%Choice%"=="cp" (GOTO Case6) else (
if "%Choice%"=="kp" (GOTO Case7) else (
if "%Choice%"=="?" (GOTO CaseHelp) else (
if "%Choice%"=="c" (GOTO Case8) else (
if "%Choice%"=="sl" (GOTO Case9) else (
if "%Choice%"=="sf" (GOTO Case10) else (
if "%Choice%"=="fz" (GOTO Case11) else (
if "%Choice%"=="dc" (GOTO Case12) else (
if "%Choice%"=="cm" (GOTO Case12) else (
if "%Choice%"=="wh" (GOTO Case13) else (
if "%Choice%"=="vs" (GOTO Case14) else (
if "%Choice%"=="it" (GOTO Case15) else (
if "%Choice%"=="tm" (GOTO Case16) else (
if "%Choice%"=="d" (GOTO Case17) else (
if "%Choice%"=="ed" (GOTO Case18) else (
if "%Choice%"=="be" (GOTO Case19) else (
if "%Choice%"=="me" (GOTO Case20) else (
if "%Choice%"=="ap" (GOTO Case21) else (
if "%Choice%"=="pc" (GOTO Case22) else (
if "%Choice%"=="sc" (GOTO Case23) else (
if "%Choice%"=="c" (GOTO Case24) else (
if "%Choice%"=="ll" (GOTO Case25) else (
if "%Choice%"=="ij" (GOTO Case26) else (
GOTO CaseError)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
Also, is there an alternative of using an if statement as this method is uite time consuming.
Well, I see 28 opening (, but only 24 closing ), so it can't possibly work.
You don't show your complete relevant code, we can't see if you have all the required labels.
PaulF has a good point in his comment, since each IF does a GOTO, you don't need any ELSE statements.
if "%Choice%"=="si" GOTO Case2
if "%Choice%"=="s" GOTO Case1
if "%Choice%"=="ti" GOTO Case4
etc...
if "%Choice%"=="ij" GOTO Case26
goto CaseError
But let's suppose that you are not doing GOTO with each IF, but rather something else. There is no need to do a lot of indents, and you don't need so many parens. Batch does not formally have an ElseIf, but it functionally works just as well if you use ELSE IF. Look how I arrange the parens and indents - it is much easier to read and follow the code.
if "%Choice%"=="xxx" (
do something
) else if "%Choice%"=="yyy" (
do something else
) else if "%Choice%"=="zzz" (
do something different
) else (
everything else gets to here
)
Since you are performing GOTOs, there is another option. Incorporate the %Choice% value in the :label, and then you don't need any IF statement, other than to verify that the choice is valid, and take special action if it isn't.
Opion 1: Define the list of valid entries, and use find/replace to test if the choice is amongst the valid options. This is best done with delayed expansion. Note the leading and trailing space in the options list is important in this technique.
setlocal enableDelayedExpansion
set "options= si s ti t i cp kp ? c sl sf fz dc cm wh vs it tm d ed be me ap pc sc c ll ij "
set "choice="
set /p "choice=Enter your choice: "
if "!options: %choice% =!" neq "!options!" goto case_%choice%
goto case_error
:case_si
rem do something
exit /b
:case_s
rem do something else
exit /b
etc...
Option 2: Use FINDSTR to probe the batch file itself to verify the label exists. Here I am using a simplified search that will not handle all possible arrangements of valid labels. But it should be fine as long as you don't get creative with how you create your labels.
set "choice="
set /p "choice=Enter your choice: "
findstr /i /r /c:"^:case_%choice%$" /c:"^:case_%choice% " "%~f0" >nul 2>nul && goto :case_%choice%
goto :case_error
:Case_si
rem do something
exit /b
:Case_s
rem do something else
exit /b
etc...
I suggest to use the command CHOICE for this large selection between 28 options:
#echo off
:Menu
cls
echo 1 ... option 1
echo 2 ... option 2
echo and so on
echo 9 ... option 9
echo a ... option 10
echo and so on
echo r option 27
echo 0 ... help
echo/
%SystemRoot%\System32\choice.exe /C 123456789abcdefghijklmnopqr0 /N /M "Your choice: "
goto Case%ERRORLEVEL%
:Case1
echo Option 1
goto :EOF
:Case2
echo Option 2
goto :EOF
rem And so on
:Case28
cls
echo Help
echo/
pause
goto :Menu
Command CHOICE does not allow any invalid input. It waits with the used options until the user presses any key as specified after parameter /C and assigns to ERRORLEVEL the number according to index of the appropriate key/character in the list, i.e. 1 for first 1, 2 for second 2 and 28 for last key/character 0. Run in a command prompt window choice /? for help on this command.
goto Case%ERRORLEVEL% is not working if the entire menu code is within a command block starting with ( and ending with matching ) because variable reference %ERRORLEVEL% is replaced already by current value of environment variable ERRORLEVEL before the command left to ( is executed at all.
Delayed expansion must be enabled in this case and goto Case!ERRORLEVEL! must be used to get the GOTO working within a command block. Run in a command prompt set /? and read the hep output on several window pages for details about delayed expansion as well as setlocal /? used to enable delayed expansion and endlocal /? to restore previous command environment.
An alternate solution for the menu within a command block without using delayed environment variable expansion is replacing the command line goto Case%ERRORLEVEL% by
for /L %%X in (28,-1,1) do if errorlevel %%X goto Case%%X
See the Microsoft support article about Testing for a Specific Error Level in Batch Files why the decrementing FOR loop with the if errorlevel X condition executing goto CaseX works within a command block without usage of delayed expansion.
I think this is the simplest way to solve this problem:
#echo off
setlocal
set /p "Choice= Which Service? "
call :Case-%choice% 2> NUL
if errorlevel 1 goto CaseError
goto :EOF
:Case-si
echo You select "si" service
exit /B
:Case-s
echo You select "s" service
exit /B
:Case-etc
echo You select "etc" service
exit /B
:CaseError
echo Error: invalid service...
goto :EOF
When a call with a non-defined label is executed, the system automatically set ERRORLEVEL to one and continue to the next line, so you just need an if to detect such an error...
Using this method you don't need to check for each one of the options, just include the desired code below each one of the proper :Case-serviceNameHere labels and that is it!

Check if a string variable is empty in batch script

I am trying to write a batch script to get a string in a variable and check if it is empty, and if it is empty then it is directed to a loop. The below code represents the problem
:loop
set /p cide=
IF NOT "a%1"=="a" (set cide="%1")
IF [%1]==[] goto loop
ELSE
echo IDE entered
TIMEOUT 5 > NUL
The program starts to loop again even if i give a string.
I tried to put IF [%cide%]==[] goto loop or IF %cide%==[] goto loop it gave an error stating "ELSE" not recognized.
Any help is appreciated. Thanks
You can try something like that :
#echo off
:loop
cls & Color 0A
echo Type what you want !
set /p "cide="
IF "%cide%"=="" (
Cls & Color 0C
echo You must enter something
Timeout /T 2 /NoBreak>nul
goto loop
) ELSE (
Goto Next
)
:Next
Cls
echo %cide% is entered
pause
#echo off
:loop
cls & Color 0A
echo Type what you want !
set /p "cide="
IF [%cide%]==[] (
Cls & Color 0C
echo You must enter something
choice /d y /t 2 > nul
goto loop
) ELSE (
Goto Next
)
:Next
Cls
echo %cide% is entered
pause

Batch - If, ElseIf, Else

Whats wrong with this code?
IF "%language%" == "de" (
goto languageDE
) ELSE (
IF "%language%" == "en" (
goto languageEN
) ELSE (
echo Not found.
)
I'm not really good in Batch..
#echo off
title Test
echo Select a language. (de/en)
set /p language=
IF /i "%language%"=="de" goto languageDE
IF /i "%language%"=="en" goto languageEN
echo Not found.
goto commonexit
:languageDE
echo German
goto commonexit
:languageEN
echo English
goto commonexit
:commonexit
pause
The point is that batch simply continues through instructions, line by line until it reaches a goto, exit or end-of-file. It has no concept of sections to control flow.
Hence, entering de would jump to :languagede then simply continue executing instructions until the file ends, showing de then en then not found.
#echo off
set "language=de"
IF "%language%" == "de" (
goto languageDE
) ELSE (
IF "%language%" == "en" (
goto languageEN
) ELSE (
echo Not found.
)
)
:languageEN
:languageDE
echo %language%
This works , but not sure how your language variable is defined.Does it have spaces in its definition.
batchfiles perform simple string substitution with variables.
so, a simple
goto :language%language%
echo notfound
...
does this without any need for if.
Recommendation. Do not use user-added REM statements to block batch steps. Use conditional GOTO instead.
That way you can predefine and test the steps and options. The users also get much simpler changes and better confidence.
#Echo on
rem Using flags to control command execution
SET ExecuteSection1=0
SET ExecuteSection2=1
#echo off
IF %ExecuteSection1%==0 GOTO EndSection1
ECHO Section 1 Here
:EndSection1
IF %ExecuteSection2%==0 GOTO EndSection2
ECHO Section 2 Here
:EndSection2
#echo off
color 0a
set /p language=
if %language% == DE (
goto LGDE
) else (
if %language% == EN (
goto LGEN
) else (
echo N/A
)
:LGDE
(code)
:LGEN
(code)

Switch statement equivalent in Windows batch file

I wonder if there is a simple way to branch execution in a Windows batch file depending on the value of one single expression. Something akin to switch/case blocks in C, C++, C#, Java, JavaScript, PHP, and other real programming languages.
My only workaround is a plain if/else block where the same expression is repeatedly checked for equality against different values:
IF "%ID%"=="0" (
REM do something
) ELSE IF "%ID%"=="1" (
REM do something else
) ELSE IF "%ID%"=="2" (
REM do another thing
) ELSE (
REM default case...
)
So dumb. Is there a better solution?
I ended up using label names containing the values for the case expressions as suggested by AjV Jsy. Anyway, I use CALL instead of GOTO to jump into the correct case block and GOTO :EOF to jump back. The following sample code is a complete batch script illustrating the idea.
#ECHO OFF
SET /P COLOR="Choose a background color (type red, blue or black): "
2>NUL CALL :CASE_%COLOR% # jump to :CASE_red, :CASE_blue, etc.
IF ERRORLEVEL 1 CALL :DEFAULT_CASE # If label doesn't exist
ECHO Done.
EXIT /B
:CASE_red
COLOR CF
GOTO END_CASE
:CASE_blue
COLOR 9F
GOTO END_CASE
:CASE_black
COLOR 0F
GOTO END_CASE
:DEFAULT_CASE
ECHO Unknown color "%COLOR%"
GOTO END_CASE
:END_CASE
VER > NUL # reset ERRORLEVEL
GOTO :EOF # return from CALL
This is simpler to read:
IF "%ID%"=="0" REM do something
IF "%ID%"=="1" REM do something else
IF "%ID%"=="2" REM do another thing
IF %ID% GTR 2 REM default case...
Compact form for short commands (no 'echo'):
IF "%ID%"=="0" ( ... & ... & ... ) ELSE ^
IF "%ID%"=="1" ( ... ) ELSE ^
IF "%ID%"=="2" ( ... ) ELSE ^
REM default case...
After ^ must be an immediate line end, no spaces.
I guess all other options would be more cryptic. For those who like readable and non-cryptic code:
IF "%ID%"=="0" (
REM do something
) ELSE IF "%ID%"=="1" (
REM do something else
) ELSE IF "%ID%"=="2" (
REM do another thing
) ELSE (
REM default case...
)
It's like an anecdote:
Magician: Put the egg under the hat, do the magic passes ... Remove the hat and ... get the same egg but in the side view ...
The IF ELSE solution isn't that bad. It's almost as good as python's if elif else. More cryptic 'eggs' can be found here.
I searched switch / case in batch files today and stumbled upon this. I used this solution and extended it with a goto exit.
IF "%1"=="red" echo "one selected" & goto exit
IF "%1"=="two" echo "two selected" & goto exit
...
echo "Options: [one | two | ...]
:exit
Which brings in the default state (echo line) and no extra if's when the choice is found.
Hariprasad didupe suggested a solution provided by Batchography, but it could be improved a bit. Unlike with other cases getting into default case will set ERRORLEVEL to 1 and, if that is not desired, you should manually set ERRORLEVEL to 0:
goto :switch-case-N-%N% 2>nul || (
rem Default case
rem Manually set ERRORLEVEL to 0
type nul>nul
echo Something else
)
...
The readability could be improved for the price of a call overhead:
call:Switch SwitchLabel %N% || (
:SwitchLabel-1
echo One
goto:EOF
:SwitchLabel-2
echo Two
goto:EOF
:SwitchLabel-3
echo Three
goto:EOF
:SwitchLabel-
echo Default case
)
:Switch
goto:%1-%2 2>nul || (
type nul>nul
goto:%1-
)
exit /b
Few things to note:
As stated before, this has a call overhead;
Default case is required. If no action is needed put rem inside to
avoid parenthesis error;
All cases except the default one are executed in the sub-context. If
you want to exit parent context (usually script) you may use this;
Default case is executed in a parent context, so it cannot be
combined with other cases (as reaching goto:EOF will exit parent
context). This could be circumvented by replacing goto:%1- in
subroutine with call:%1- for the price of additional call overhead;
Subroutine takes label prefix (sans hyphen) and control variable. Without label
prefix switch will look for labels with :- prefix (which are valid) and
not passing a control variable will lead to default case.
Try by this way. To perform some list of operations like
Switch case has been used.
Checking the conditional statements.
Invoking the function with more than two arguments.
#echo off
:Start2
cls
goto Start
:Start
echo --------------------------------------
echo Welcome to the Shortcut tool
echo --------------------------------------
echo Choose from the list given below:
echo [1] 2017
echo [2] 2018
echo [3] Task
set /a one=1
set /a two=2
set /a three=3
set /a four=4
set input=
set /p input= Enter your choice:
if %input% equ %one% goto Z if NOT goto Start2
if %input% equ %two% goto X if NOT goto Start2
if %input% equ %three% goto C if NOT goto Start2
if %input% geq %four% goto N
:Z
cls
echo You have selected year : 2017
set year=2017
echo %year%
call:branches year
pause
exit
:X
cls
echo You have selected year : 2018
set year=2018
echo %year%
call:branches year
pause
exit
:C
cls
echo You have selected Task
call:Task
pause
exit
:N
cls
echo Invalid Selection! Try again
pause
goto :start2
:branches
cls
echo Choose from the list of Branches given below:
echo [1] January
echo [2] Feburary
echo [3] March
SETLOCAL
set /a "Number1=%~1"
set input=
set /p input= Enter your choice:
set /a b=0
set /a bd=3
set /a bdd=4
if %input% equ %b% goto N
if %input% leq %bd% call:Z1 Number1,input if NOT goto Start2
if %input% geq %bdd% goto N
:Z1
cls
SETLOCAL
set /a "Number1=%~1"
echo year = %Number1%
set /a "Number2=%~2"
echo branch = %Number2%
call:operation Number1,Number2
pause
GOTO :EOF
:operation
cls
echo Choose from the list of Operation given below:
echo [1] UB
echo [3] B
echo [4] C
echo [5] l
echo [6] R
echo [7] JT
echo [8] CT
echo [9] JT
SETLOCAL
set /a "year=%~1"
echo Your have selected year = %year%
set /a "month=%~2"
echo You have selected Branch = %month%
set operation=
set /p operation= Enter your choice:
set /a b=0
set /a bd=9
set /a bdd=10
if %input% equ %b% goto N
if %operation% leq %bd% goto :switch-case-N-%operation% if NOT goto Start2
if %input% geq %bdd% goto N
:switch-case-N-1
echo Januray
echo %year%,%month%,%operation%
goto :switch-case-end
:switch-case-N-2
echo Feburary
echo %year%,%month%,%operation%
goto :switch-case-end
:switch-case-N-3
echo march
echo %year%,%month%,%operation%
goto :switch-case-end
:switch-case-end
echo Task Completed
pause
exit
goto :start2
:Task
cls
echo Choose from the list of Operation given below:
echo [1] UB
echo [3] B
echo [4] C
echo [5] l
echo [6] R
echo [7] JT
echo [8] CT
echo [9] JT
SETLOCAL
set operation=
set /p operation= Enter your choice:
set /a b=0
set /a bd=9
set /a bdd=10
if %input% equ %b% goto N
if %operation% leq %bd% goto :switch-case-N-%operation% if NOT goto Start2
if %input% geq %bdd% goto N
:switch-case-N-1
echo Januray
echo %operation%
goto :switch-case-end
:switch-case-N-2
echo Feburary
echo %year%,%month%,%operation%
goto :switch-case-end
:switch-case-N-3
echo march
echo %year%,%month%,%operation%
goto :switch-case-end
:switch-case-end
echo Task Completed
pause
exit
goto :start2
If if is not working you use:
:switch case %n%=1
statements;
goto :switch case end
etc..
http://lallouslab.net/2016/12/21/batchography-switch-case/
It might be a bit late, but this does it:
set "case1=operation1"
set "case2=operation2"
set "case3=operation3"
setlocal EnableDelayedExpansion
!%switch%!
endlocal
%switch% gets replaced before line execution. Serious downsides:
You override the case variables
It needs DelayedExpansion
Might eventually be usefull in some cases.

Checking input via a batch file

I am doing user input and checking to see if they typed n or y... and it's not working because it says both either way.
Here's what I have:
#echo off
set /P theuserinput="Type your name: "
echo So your name is: %theuserinput%?
set /P isit="Y/N: "
echo You typed: %isit%
if (%isit% == "y") goto :saidyes
if (%isit% == "n") goto :saidno
:saidyes
echo Hooray!
:saidno
echo Aww
PAUSE
First you can add a default goto after the two if's.
Then, in both tests you have to add the quotes around %isit% and to remove the parenthesis. You may also add the /I flag to do an insensitive string comparison.
Finally, add goto after each echo to jump over the next one.
#echo off
set /P theuserinput="Type your name: "
echo So your name is: %theuserinput%?
set /P isit="Y/N: "
echo You typed: %isit%
if /I "%isit%" == "Y" goto :saidyes
if /I "%isit%" == "N" goto :saidno
goto :error
:saidyes
echo Hooray!
goto :end
:saidno
echo Aww
goto :end
:error
echo ERROR
:end
PAUSE
Need change in syntax
Here is the modified code
#echo off
set /P theuserinput="Type your name: "
echo So your name is: %theuserinput%?
set /P isit="Y/N: "
echo You typed: %isit%
if "%isit%" == "Y" GOTO saidyes
if "%isit%" == "N" GOTO saidno
:saidyes
echo Hooray!
GOTO paused
:saidno
echo Aww
:paused
PAUSE
....
In above example The Y/N is supposed to be capital letter only.
There are a few things I would do differently to this to ensure that it works properly...
First off the corrected code is the following, but at the bottom is my suggested code:
#echo off
setlocal
set theuserinput=
set /P theuserinput="Type your name: "
echo So your name is: %theuserinput%?
set /P isit="Y/N: "
echo You typed: %isit%
if '%isit%'== 'Y' goto saidyes
if '%isit%'=='N' goto saidno
:saidyes
echo Hooray!
goto end
:saidno
echo Aww
goto end
:end
pause
endlocal
exit
However, to make sure that you only get Y or N there are a few things I would put in...
First I would make sure that you only grab the first letter by adding:
IF NOT '%isit%'=='' set isit=%isit:~0,1%
Next I would make sure that you only have Capital letters, so you make the swap if they are lowercase, because this will actually not work in some cases if the CaSe isn't correct:
if '%isit%'== 'y' set isit=Y
if '%isit%'== 'Y' goto :saidyes
if '%isit%'=='n' set isit=N
if '%isit%'=='N' goto :saidno
The final edit for this file could look like the following:
#echo off
:top
set theuserinput=
set /P theuserinput="Type your name: "
echo So your name is: %theuserinput%?
set /P isit="Y/N: "
IF NOT '%isit%'=='' set isit=%isit:~0,1%
IF '%isit%'=='y' set isit=Y
IF '%isit%'=='Y' goto saidyes
IF '%isit%'=='n' set isit=N
IF '%isit%'=='N' goto saidno
goto top
:saidyes
echo You typed: %isit%
echo Hooray!
goto end
:saidno
echo You typed: %isit%
echo Aww
goto end
:end
pause
exit
Quotes are commonly misused in DOS batch files. Unlike UNIX shell scripts, the DOS batch language is not thought-out. For example, when the isit variable contains quotes
set isit="Y"
then the above if-statements expand to
IF ""Y"" == "Y" GOTO saidyes
IF ""Y"" == "N" GOTO saidno
because cmd.exe does not remove the quotes in "%isit%"=="Y" before evaluating the expression.
Quotes in isit shall not occur with the original batch file posted here. But often you process path names in batch files, and Windows passes long file names in quotes to hide blanks. For example, as in "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC". To work around this it is common practice to write if-statements so:
IF ["%isit%"] == ["Y"] GOTO saidyes
IF [%isit%] == ["Y"] GOTO saidyes
IF [%isit%] == [Y] GOTO saidyes
For set isit="Y" this becomes:
IF [""Y""] == ["Y"] GOTO saidyes
IF ["Y"] == ["Y"] GOTO saidyes
IF ["Y"] == [Y] GOTO saidyes
and for set isit=Y:
IF ["Y"] == ["Y"] GOTO saidyes
IF [Y] == ["Y"] GOTO saidyes
IF [Y] == [Y] GOTO saidyes
and for set isit=:
IF [""] == ["Y"] GOTO saidyes
IF [] == ["Y"] GOTO saidyes
IF [] == [Y] GOTO saidyes
which is far from being elegant, but at least works now for quoted and unquoted variables. It also works when isit is empty. Oftenly batch files stop because of empty variables:
set x=
REM ...
IF %x% == x GOTO x
because now the if-statement expands to:
IF == x GOTO x
and cmd.exe fails. These errors are usually hard to debug.
The trick is very old; I remember using it already in MSDOS. Note that the square brackets are not evaluated by cmd.exe; they're just some rarely used characters. But it's just a trick. Any advanced batch script needs a dequoting-function:
#echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion
REM ...
set /P isit="Y/N: "
call :dequote isit
REM ...
IF "!isit!" == "Y" GOTO saidyes
IF "!isit!" == "N" GOTO saidno
REM ...
goto done
:dequote
for /f "delims=" %%A in ('echo %%%1%%') do set %1=%%~A
goto :eof
:done
The deqote-subroutine removes any double quotes around the variable name passed to the function.
After dequoting the []-trick is not required anymore. Note also the use of ! instead of %. The exclamation marks force cmd.exe to reexpand isit.
I changed the code somewhat to help fix your problem. Instead of goto :(function) you just say goto (function)
#echo off
set /P theuserinput=Type your name:
echo So your name is: %theuserinput%?
set /p isit=Y/N:
echo You typed: %isit%
if %isit% == "y" goto saidyes
if %isit% == "n" goto saidno
:saidyes
echo Hooray!
:saidno
echo Aww
pause

Resources