ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[¤À¨É] BAT§å¦¸«ü¥O¡G GOTO ªº¥\¯à¤¶²Ð

[¤À¨É] BAT§å¦¸«ü¥O¡G GOTO ªº¥\¯à¤¶²Ð

BAT§å¦¸«ü¥O¡G GOTO ªº¥\¯à¤¶²Ð

Goto :±N cmd.exe ¾É¦V¦Ü§å¦¸µ{¦¡¸Ì¼ÐÅÒ«ü©wªº©w¦ì¡C

«ü¥O¸Ô¸Ñ:

GOTO label

  label   «ü©w§å¦¸µ{¦¡¸Ì°µ¬°¼ÐÅÒ¦WºÙªº¤å¦r¦r¦ê¡C

¼ÐÅÒ¦WºÙ¥²¶·­Ó§O¤@¦æ¡A¨Ã¥B¥H«_¸¹¶}ÀY¡C

¦pªG±z±Ò°ÊÂX¥R«ü¥O¡AGOTO «ü¥OªºÅܧó¤U¦C:

GOTO «ü¥O±µ¦¬¨ì¤@­Óª«¥ó¼ÐÅÒ: EOF¡A¦Ó¦¹¼ÐÅÒ·|±N±±¨î¶Ç°e¦Ü¥Ø«e§å¦¸«ü¥OÀɪº§ÀºÝ¡C
§Q¥Î¦¹Â²³æªº¼Ò¦¡¡A¥i¤£¥²©w¸q¼ÐÅÒ«K§YÂ÷¶}§å¦¸«ü¥OÀÉ¡C
¿é¤J CALL /? ¥HÀ˵ø¦³ÃöCALL ÂX¥R«ü¥Oµo´§¦¹¯S©Ê­Èªº»¡©ú¡C

BAT§å¦¸«ü¥O¡G GOTO ªº¥\¯à½d¨Ò¸Ô¸Ñ- ¤@

-----------------------------------------------------------------------------------------------
• «ü¥O¡GGoto   
• »¡©ú¡G¸õ²¾¦Ü«ü©w¼ÐÅÒ¡Aµ{¦¡±N°õ¦æ«ü©w¼ÐÅÒ¤U¤@¦C¶}©lªº«ü¥O¡C
• ³Æµù¡G§@¥Î-¤£Åã¥Ü¸ê°T¡A¦³§Q©ó¨Ï¥ÎªÌ¦Û­q¸ê°T¡C
• ¥Îªk¡Ggoto lable
• °Ñ¼Æ¡Glable
• ¨Ò¦p¡G
       if {%1}=={} goto noparms
          if {%2}=={}nul

-----------------------------------------------------------------------------------------------

GOTO«ü¥O¦b§å¦¸Àɤ¤¥Î¨ÓÂಾ±±¨î¥[Åv¡A¥i¥H«ü¥Ü§å¦¸Àɸõ¦Ü¬Y¤@ºX¼Ð¡]line label¡^¥Ñ¤@­Ó«_¸¹¡]¡G¡^¸òµÛ¦r¤¸²Å¸¹©Ò²Õ¦¨ªº¡Flabel¤]¥i¨Ï¥Î¥N´«ÅܼơC
Ex¡G
goto first ©Î goto %1

½d¨Ò:
«Ø¥ßTEST6.BAT¡AÀɤº®e¤U¦C¡G
@ECHO OFF
IF EXIST C:\AUTOEXEC.BAT GOTO _COPY
GOTO _DONE
:_COPY
COPY C:\AUTOEXEC.BAT D:\
:_DONE

ª`·N¡G
(1) ¼Ð¼m«e¬OASCII¦r¤¸ªº«_¸¹":"¡A«_¸¹»P¼Ð¼m¤§¶¡¤£¯à¦³ªÅ¥Õ¦r¤¸¡C
(2) ¼Ð¼mªº©R¦W³W«h»PÀɮצWªº©R¦W³W«h¬Û¦P¡C
(3) DOS¤ä´©³Ìªø¤K¦ì¤¸¦r¤¸ªº¼Ð¼m¡A·íµLªk°Ï§O¨â­Ó¼Ð¼m®É¡A±N¸õÂà¦Ü³Ìªñªº¤@­Ó¼Ð¼m¡C

==== ª` =====================================================
1)¼Ð¼m¤]ºÙ§@¼ÐÅÒ(label)
2)¼ÐÅÒ¤£¯à¥H¤j¦h¼Æªº«D¦r¥À¼Æ¦r¦r¤¸¶}©l, ¦ÓÀɮצW¤¤«h¥i¥H¨Ï¥Î«Ü¦h
3)·íµLªk°Ï§O¨â­Ó¼ÐÅÒ®É, ±N¸õÂà¦Ü©w¦ì³Ì¾a«eªº¼ÐÅÒ
========================================================================

TOP

BAT§å¦¸«ü¥O¡G GOTO ªº¥\¯à½d¨Ò¸Ô¸Ñ- ¤G

cmd goto«ü¥O ¬yµ{¸õÂà

goto §å¦¸³B²z§@·~ÀÉ®×°õ¦æ¦Ü³o¸Ì±N«e©¹goto©Ò«ü©wªººX¼Ð(ºX¼Ð§Ylabel¡AºX¼Ð¥Î : «á¸ò¼Ð·Ç¤å¦r¦ê¨Ó©w¸q)³B¡Agoto±Ô­z¤@¯ë»Pif°t¦X¨Ï¥Î¡A®Ú¾Ú¤£¦Pªº±ø¥ó¨Ó°õ¦æ¤£¦Pªº«ü¥O²Õ¡C

¦p:

goto end

:end
echo this is the end

ºX¼Ð¥Î" : ¤å¦r¦ê"¨Ó©w¸q¡AºX¼Ð©Ò¦b¦æ¤£³Q°õ¦æ¡C

¤@¯ëªº§å¦¸³B²z§@·~«ü¥O¡A³£¬O¨Ì·Ó¦Û¤W¦Ó¤Uªº¬yµ{³v¦C°õ¦æªº¡A¤]´N¬O»¡¡A¥u¦³²Ä¤@¦Cªº«ü¥O°õ¦æ¤F¤§«á¡A¤~¯à¯à°õ¦æ²Ä¤G¦C¡A²Ä¤G¦C°õ¦æ§¹¤§«á¡A¦A°õ¦æ²Ä¤T¦C¡K¡K¦p¦¹¨Ì§Ç°õ¦æ¡C

¦pªG¹ï¤£¦Pªº±¡ªp¡A»Ý­n°õ¦æ¤£¦Pªº¬J©w¾Þ§@¡A­YÁÙ¬O¨Ì·Ó¤@¯ëªº°õ¦æ¬yµ{ªº¸Ü¡A¬OµLªk§¹¦¨¤u§@ªº¡A³o­Ó®É­Ô¡A´N»Ý­n¤Þ¤J¬yµ{¸õÂ઺·§©À¡A°Ê¥Î¬yµ{¸õÂà±Ô­z goto ¤F¡C

¬yµ{¸õÂ઺§t¸q¬O¡G§ïÅܹw³]ªº°õ¦æ¶¶§Ç¡A±j¨î¸õ²¾¦Ü«ü©wªº©w¦ì°õ¦æ¯S©wªºµ{¦¡¶ô¡C

½d¨Ò¡G°²³]»Ý­n§PÂ_¨Ï¥ÎªÌ¿é¤Jªº¬OAÁÙ¬OB¡A­ì©l½X¥i¥H¼g¦¨³o¼Ë¡G

@echo off
set /p input=½Ð¿é¤J¦r¥ÀA©ÎB¡G
if "%input%"=="A" goto A
if "%input%"=="B" goto B
pause
exit

:A
echo ±z¿é¤Jªº¦r¥À¬OA
pause
exit

:B
echo ±z¿é¤Jªº¦r¥À¬OB
pause
exit ¡@¡@

¨Ì·Ó¤@¯ëªº°õ¦æ¬yµ{¡A¥þ³¡ªº­ì©l½X³£·|¦Û¤W¦Ó¤U³v¦C°õ¦æ¤@¦¸¡Aµ²ªG±NÅã¥Ü"±z¿é¤Jªº¦r¥À¬OA"©M"±z¿é¤Jªº¦r¥À¬OB"³o¨â¦C¤º®e¡A«ÜÅãµM¡A³o¬O¹F¤£¨ì§Ú­Ìªº­n¨Dªº¡F
¦ý¬O¡A¹ê»Úªºµ²ªG¬O¡G¦pªG±z¿é¤Jªº¦r¥À«DA§YB¡A«hµ²ªG¥u·|Åã¥Ü"±z¿é¤Jªº¦r¥À¬OA"©ÎªÌ"±z¿é¤Jªº¦r¥À¬OB"¡F
¤]´N¬O»¡¡A­ì©l½Xªº°õ¦æ¶¶§Çµo¥Í¤F§ïÅÜ¡A¤£¦A¤@¦¨¤£Åܦa¦Û¤W¦Ó¤U³v¦C°õ¦æ¤F¡G·í¿é¤J¦r¥ÀA«á¡A±N°õ¦æ²Ä¤@±øif±Ô­z¡A¦¹±ø±Ô­z°õ¦æ«á¡A±N¸õ²¾¦Ü¼ÐÅҰϬq:A¡A±q¦Ó¶¹L¤F²Ä¤@±øif±Ô­z©M:A¤§¶¡ªº¥þ³¡­ì©l½X¦C¡F
·í¿é¤J¦r¥ÀB«á¡A±N°õ¦æÀY¨â±øif±Ô­z¡A·í°õ¦æ§¹²Ä¤G±øif±Ô­z«á¡A±N¸õ²¾¦Ü¼ÐÅҰϬq:B¡A±q¦Ó¶¹L¤F²Ä¤G±øif±Ô­z©M:B¤§¶¡ªº¥þ³¡­ì©l½X¦C¡C

±q¤W­±ªº¨Ò¤l¥i¥H¬Ý¦Ü¡A­nÅýgoto±Ô­z°_§@¥Î¡AÁٻݭn:A©Î:B¤§Ãþªº¼ÐÅҰϬqªº°t¦X¡C
©Ò¿×ªº¼ÐÅҰϬq¡A´N¬O³o¼Ëªº¤@¨Ç­ì©l½X¶ô¡G¦b­º¦C¤W¥H³æ­Ó«_¸¹¥´ÀY¡A¨ä«áºò¸ò¤@¦r¦ê¦r¤¸¡A²Ä¤G¦C¤Î¨ä¤§«áªº¥þ³¡¦C¬°­ì©l½X±Ô­z¦C¡C
¦b³o¸Ì¡A²Ä¤@¦Cªº«_¸¹¬O¼ÐÅҼмm¡Aºò¸ò¥L¤§«áªº¤å¦r¦ê¬O¼ÐÅÒ¦W¡A¨âªÌ¦XºÙ¼ÐÅÒ¡C
goto±Ô­z«á­±ªº³¡¤À¬°¼ÐÅÒ¦W¡A«ü¤ÞµÛ¸Ó±Ô­z°õ¦æ§¹¤§«á¸Ó«e©¹Âà¦ó¤è¡A¼ÐÅÒ«h±µ¦¬goto±Ô­zªº¸õÂà«ü¥O¡A±Ò°Êµ{¦¡µÛgoto±Ô­zªº«áÄò¾Þ§@¡C
goto±Ô­z©M¼ÐÅÒ¤¬¬Û©IÀ³¡A¦b¹ê²{¬yµ{¸õÂà®É¬Û»²¬Û¦¨¡A¯Ê¤@¤£¥i¡C

¨Ï¥Î¸õÂà±Ô­zgotoªºª`·N¨Æ¶µ¡G
1¡Bgoto±Ô­z©M¼ÐÅÒ­n¤¬¬Û©IÀ³¡A¤£¯à¥u¦³goto±Ô­z¦Ó¨S¦³¬Û¹ïªº¼ÐÅҰϬq¡A§_«h¡Aµ{¦¡±N§ä¤£¦Ü¬Û¹ïªº¼ÐÅҰϬq¦Óª½±µµ²§ô¡F¥u¦³¼ÐÅҰϬq¦Ó¨S¦³goto±Ô­z¬O®e³\ªº¡A¦ý¤£¯à¹ê²{¬yµ{¸õÂà¥\¯à¡A±q­ì©l½Xºë²ªº¨¤«×¨Ó¬Ý¡A¦³¼ÐÅҰϬq¦Ó¨S¦³goto±Ô­z¡A«h¦¹¼ÐÅÒ¬O¦h¾lªº¡A¥i¥Hºë²±¼¡F
2¡B­Y¦³¦h­Ó¼ÐÅҰϬq¡A«h»Ý­nª`·N¼ÐÅҰϬq¤§¶¡¬O§_»Ý­n·s¼W¦X¾Aªºµ²§ô±Ô­z¨Ó²×¤îµ{¦¡Ä~Äò¦V¤U°õ¦æ¡A³o¬O«Ü¦h·s¤â«Ü®e©ö¥Ç¿ùªº¦a¤è¡A»Ý­nÂÔ·V¡C
3¡B¥H¤W­±³o°Ï¬q­ì©l½X¬°¨Ò¡A¦pªG¥h±¼:A©M:B¤§¶¡ªºexit±Ô­z¡A¨º»ò¡A·í¿é¤J¦r¥ÀA¤§«á¡Aµ²ªG±N¦P®ÉÅã¥Ü"±z¿é¤Jªº¦r¥À¬OA"©M"±z¿é¤Jªº¦r¥À¬OB"³o¨â¦C¤º®e¡A¦Ó«O¯dexit±Ô­z±N¥u·|¦bÅã¥Ü"±z¿é¤Jªº¦r¥À¬OA"«á¡A«ö¥ô·NÁä±À¥X§å¦¸³B²z§@·~µ{¦¡¡A¦]¬°§å¦¸³B²z§@·~¬O¦Û¤W¦Ó¤U³v¦C°õ¦æªº¡A§Y¨Ï¥Îgoto±Ô­z¸õÂध«á¡A¦b·sªº©w¦ì¤W¡A³o¤@°õ¦æ¬yµ{¤´µM·|«O«ù¡Aª½¦Ü¸I¤W¥t¤@­Ó¬yµ{¸õÂà±Ô­z¡A°õ¦æµ{§Ç¨Ã¤£·|¦b¨â­Ó¼ÐÅҰϬq¤§¶¡¦Û°Ê²×¤î¡C
3¡B¼ÐÅÒ¦W¥u¥i¥H¨Ï¥Î±`¶q¡A¦Ó¤£¯à¨Ï¥ÎÅܼơF­Y¦³¦P¦WºÙªº¼ÐÅҰϬq¡A±N°õ¦æ¦ì©ó³Ì³»¼hªº¼ÐÅҰϬq¡A¨ä«áªº¼ÐÅҰϬq¬O§_±o¦Ü°õ¦æ¡A±Nµø¨ãÅ骺±¡ªp¥[¥H³B²z¡C

TOP

BAT§å¦¸«ü¥O¡G GOTO ªº¥\¯à½d¨Ò¸Ô¸Ñ- ¤T


:
©M goto


¬°¤°»ò­n§â³o¨â­Ó«ü¥OÁp¦X°_¨Ó¤¶²Ð¡H¦]¬°¥L­Ì¬O¤À¤£¶}ªº¡AµL½×¤Ö¤F­þ­Ó©Î¦h¤F­þ­Ó³£·|µo¥Í¿ù»~¡C

goto¬O­Ó¸õÂà«ü¥O¡A" : "¬O¤@­Ó¼ÐÅÒ¡C·íµ{¦¡°õ¦æ¦Ügoto®É¡A±N¦Û°Ê¸õ²¾¦Ü" : "©w¸qªº³¡¤À¥h°õ¦æ¤F¡]¬O¤£¬O¤À¤£¶}¡H¡^¡C

½d¨Ò¤¤¦æ­º¥X²{¤@­Ó" : "

:usage
::set usage

«hµ{¦¡¦b°õ¦æ¦Ügoto®É´N¦Û°Ê¸õ²¾¦Ü" : "¼ÐÅÒ©w¸qªº³¡¤À°õ¦æ¡Aµ²ªG¬OÅã¥Ü«ü¥O½Xusage¡]usage´N¬O¼ÐÅÒ¦WºÙ¡^¡C

¤£Ãø¬Ý¥X¡Agoto«ü¥O´N¬O®Ú¾Ú³o­Ó«_¸¹©M¼ÐÅÒ¦WºÙ¨Ó´M§ä¥L¸Ó¸õÂ઺¦a¤è¡A¥¦­Ì¬O¤@¤@¹ïÀ³ªºÃö«Y¡C

goto«ü¥O¤]¸g±`©M if «ü¥Oµ²¦X¨Ï¥Î¡C

¦Ü©ó³o¨â­Ó«ü¥O¨ãÅé¥Îªk¡A°Ñ·Ó½d¨Ò:

if "%1"=="" goto usage
::if input without paramater goto usage
if "%1"=="/?" goto usage
::if paramater is "/?" goto usage
if "%1"=="help" goto usage
::if paramater is "help" goto usage
pause
::pause to see usage

goto«ü¥Oªº¥t¤@ºØ¥Îªk¤@¡G´£«eµ²§ôµ{¦¡¡C
¦bµ{¦¡¤¤¶¡¨Ï¥Îgoto«ü¥O¸õ²¾¦Ü¬Y¤@¼ÐÅÒ¡A¦Ó³o¤@¼ÐÅÒªº¤º®e«o©w¸q¬°µ²§ô¡C

¨Ò¦p¡G

¡K¡K
goto end
¡K¡K
:end
ªF­·

TOP

        ÀR«ä¦Û¦b : ¦¨¥\¬OÀuÂIªºµo´§¡A¥¢±Ñ¬O¯ÊÂIªº²Ö¿n¡C
ªð¦^¦Cªí ¤W¤@¥DÃD