If a variable equals, for example 1
then goto
to start1
BUT if the same variable equals 2
then goto
to start2
.
This is what i have so far:
if %method% == "1" (goto start1)
if %method% == "2" (goto start2)
:start1
echo start1
pause
exit
:start2
echo start2
pause
exit
But even if the method
variable is equals 2
it always echo me start1
...
[ == ] (Double Equals) The "IF" command uses this to test if two strings are equal: IF "%1" == "" GOTO HELP. means that if the first parameter on the command line after the batch file name is equal to nothing, that is, if a first parameter is not given, the batch file is to go to the HELP label.
One of the common uses for the 'if' statement in Batch Script is for checking variables which are set in Batch Script itself. The evaluation of the 'if' statement can be done for both strings and numbers.
You have to be careful with whitespace. Write
if "%method%"=="1" (goto start1)
etc instead. You may or may not need the extra quotations around %method%
, depending on how you've set up your envrionment variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With