|
|
GOTO
Direct a batch program to jump to a labelled line.
syntax GOTO label
key
label : a predefined label in the batch program. Each label must be on a line by itself, beginning with a colon.
For example:
IF %1==12 GOTO s_december
:: other commands
:s_december
GOTO :eof
An easy way to exit a batch script file without defining a label is to specify
GOTO :eof
this transfers control to the end of the current batch file.
Using a variable as a label
CHOICE
goto s_routine_%ERRORLEVEL%
:s_routine_0
echo You typed Y for yes
:s_routine_1
echo You typed N for no
Skipping commands by using a variable as an optional :: (REM)
comment
In this example the 2 COPY commands will only run if the parameter "Update_Now"
is supplied to the batch
@echo off
setlocal
IF [%1]==[] GOTO :eof
IF /I NOT %1==Update_Now SET v_skip=::
%v_skip% COPY x:\update.dat
echo Your WWW connection is up to date
%v_skip% COPY x:\FTP.dat
echo Your FTP connection is up to date
Related Commands:
IF -
CALL -
If Command Extensions are disabled GOTO will no longer
recognise the :EOF label
Equivalent Linux BASH commands:
case - Conditionally perform a command