批處理中的多種注釋方法

來源:互聯網
上載者:User

標籤:

有些時候,我們需要在批處理中使用大段的注釋,即連續的注釋超過2行。那麼,如何?他呢?

  方法有很多種,本文僅列舉其中的一部分。

 

㈠、使用rem

 

注意:注釋中不能使用重新導向符和管道符;

   當回顯處於開啟是時,rem 命令及注釋內容將被顯示;

   rem 和注釋之間要有空格。

樣本:

 

 

rem 注釋內容1

rem 注釋內容2

rem 注釋內容3

 

 

㈡、使用::

 

  Windows XP 可以識別以冒號 (:) 開頭作為標籤的批次程式行並且不會將它作為命令處理。如果某行以冒號開始,則該行的任何命令都將被忽略。

樣本:

 

 

:: 注釋內容1

:: 注釋內容2

:: 注釋內容3

 

㈢、使用echo >nul

 

注意:注釋中不能使用重新導向符和管道符;

   echo 和注釋之間要有空格。

樣本:

 

 

echo 注釋內容1>nul

echo 注釋內容2>nul

echo 注釋內容3>nul

 

㈣、使用goto

 

注意:注釋中不能使用goto 指向的標籤

樣本:

 

 

 

 

goto han 

注釋內容1

注釋內容2

注釋內容3

:han

 

㈤、使用:注釋

 

注意:注釋中第一個字元不能是數字或字母;

樣本:

 

 

:注釋內容1

:注釋內容2

:注釋內容3

說明:在實際使用中,例如標籤 :stsrt ,我們也可以認為他是注釋。如下例:

 

:: ArgParse.bat - Parser of command line arguments
:: Will Sort - 2005-11-26 - WinXP_CMD/MSDOS7.10/MSDOS6.22
@echo off

:Init
for %%e in (directory_i directory_o filter_f filter_v log) do set%%e=

:ParseLoop
if "%1"=="" goto Start
for %%s in (i I f F v V l L o O) do if "%1"=="/%%s" gotoSwitch%%s
echo Error: Invalid switch ‘%1‘!
goto Quit

:SwitchI
if "%directory_i%"=="" set directory_i=%2
goto NextArg

:SwitchO
if "%directory_o%"=="" set directory_o=%2
goto NextArg

:SwitchF
if "%filter_f%"=="" set filter_f=%2
goto NextArg

:SwitchV
if "%filter_v%"=="" set filter_v=%2
goto NextArg

:SwitchL
if "%log%"=="" set log=%2
goto NextArg

:NextArg
shift
shift
goto ParseLoop

:Start
echo.directory_i      %directory_i%
echo.directory_o      %directory_o%
echo.filter_f        %filter_f%
echo.filter_v        %filter_v%
echo.log             %log%

:Quit
for %%e in (directory_i directory_o filter_f filter_v log) do set%%e=
:end

 

 

 

㈥、使用:標籤 注釋

 

樣本:

 

 

:han 注釋:下面的代碼。。。

命令1

命令2

 

㈦、使用if not exist nul注釋

 

注意:注釋中不能使用重新導向符和管道符;

   if not exist nul 和注釋之間要有空格。

 

樣本:

 

 

if not exist nul注釋內容1

if not exist nul 注釋內容2

if not exist nul 注釋內容3

批處理中的多種注釋方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.