@cyysu
2017-10-12T10:17:29.000000Z
字数 7121
阅读 932
- 时间:2017年10月11日
- 作者:Kali
- 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
- 版本:4.0
- 描述:批处理教程基础篇,主要介绍一些语法
Bat系列教程
我们这里的例子采用Makefile系列教程-项目篇(一),这两个脚本具有同样的功能。遇到不会的内容时刻查看help xx
# 这里先补充一下基础知识:1. 批处理文件命令行参数%[1-9]表示参数,参数是指在运行批处理文件时在文件名后加的以空格(或者Tab)分隔的字符串。变量可以从%0到%9,%0表示批处理命令本身,其它参数字符串用%1到%9顺序表示。2. 常用的基本命令和语法@echo off: 表示不回显命令执行,只显示执行结果md : 表示建立文件夹 make directoryrd : 删除文件夹ren : 重命名move : 移动文件start : 可以启动一个应用程序,打开文件夹或者文件echo : 输出描述信息pause : 程序暂停,等待任意按键按下终止程序dir : 列出当前目录goto : 跳转labelrem : 表示注释信息:: : 表示注释信息%% : 行注释信息或者获取变量set : 表示设置变量doskey : 给系统设置别名call : 调用另外一个脚本type : 列出文件内容^ : 取消该符号定义shift : 移位传入的参数,可以使用shift /? 来查看帮助CLIP : 剪切板 如 CLIP < README.TXT 表示将 readme.txt 的一份文本放入 Windows 剪贴板。%~f0 : 表示运行的文件全路径%* : 代表所有参数%~nx0 : 表示文件的名字xcopy : 强大的复制,常用示例:xcopy e:\*.* d: /s /h /d /y ::复制E盘所有内容到D盘ver : 显示系统版本# 下面来个例子来学习一下上面的命令@ echo off::设置xx变量set xx=123::设置xx1变量set xx1=456set xecho xx变量为: %xx%::调用系统变量 ERRORLEVEL表示上一条执行状态echo %os%echo %JAVA_HOME%echo %ERRORLEVEL%pause# 执行结果xx=123xx1=456xx value = 123Windows_NTD:\software\jdk1.8请按任意键继续. . .# for循环@echo offset /a total = 0:: 只查看文件夹for /d %%i in (./*) do (echo %%ipause)::查看bat文件for %%x in (*.bat) do (echo %%x)goto :end:example1::/L表示增量形式for /L %%i in (1,1,5) do (echo %%i)goto :end:example2::查找pdf的个数for %%x in (*.pdf) do (echo %%xset /a total = total + 1)goto :end:example3::输出结果信息echo %total% pdf filesgoto :end:endpause# 语法知识set /A 进行算术的命令set /p 表示从终端读取pause >nul 表示不打印输出信息wait 等待
@ECHO OFFREM Command file for Sphinx documentationif "%SPHINXBUILD%" == "" (set SPHINXBUILD=sphinx-build)set BUILDDIR=buildset ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% sourceset I18NSPHINXOPTS=%SPHINXOPTS% sourceif NOT "%PAPER%" == "" (set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%)if "%1" == "" goto helpif "%1" == "help" (:helpecho.Please use `make ^<target^>` where ^<target^> is one ofecho. html to make standalone HTML filesecho. dirhtml to make HTML files named index.html in directoriesecho. singlehtml to make a single large HTML fileecho. pickle to make pickle filesecho. json to make JSON filesecho. htmlhelp to make HTML files and a HTML help projectecho. qthelp to make HTML files and a qthelp projectecho. devhelp to make HTML files and a Devhelp projectecho. epub to make an epubecho. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letterecho. text to make text filesecho. man to make manual pagesecho. texinfo to make Texinfo filesecho. gettext to make PO message catalogsecho. changes to make an overview over all changed/added/deprecated itemsecho. xml to make Docutils-native XML filesecho. pseudoxml to make pseudoxml-XML files for display purposesecho. linkcheck to check all external links for integrityecho. doctest to run all doctests embedded in the documentation if enabledecho. coverage to run coverage check of the documentation if enabledgoto end)# /s 表示删除指定目录和其所有子目录 /q 删除内容不需要确认if "%1" == "clean" (for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%idel /q /s %BUILDDIR%\*goto end)REM Check if sphinx-build is available and fallback to Python version if any%SPHINXBUILD% 2> nulif errorlevel 9009 goto sphinx_pythongoto sphinx_ok:sphinx_pythonset SPHINXBUILD=python -m sphinx.__init__%SPHINXBUILD% 2> nulif errorlevel 9009 (echo.echo.The 'sphinx-build' command was not found. Make sure you have Sphinxecho.installed, then set the SPHINXBUILD environment variable to pointecho.to the full path of the 'sphinx-build' executable. Alternatively youecho.may add the Sphinx directory to PATH.echo.echo.If you don't have Sphinx installed, grab it fromecho.http://sphinx-doc.org/exit /b 1):sphinx_okif "%1" == "html" (%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/htmlif errorlevel 1 exit /b 1echo.echo.Build finished. The HTML pages are in %BUILDDIR%/html.goto end)if "%1" == "dirhtml" (%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtmlif errorlevel 1 exit /b 1echo.echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.goto end)if "%1" == "singlehtml" (%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtmlif errorlevel 1 exit /b 1echo.echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.goto end)if "%1" == "pickle" (%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickleif errorlevel 1 exit /b 1echo.echo.Build finished; now you can process the pickle files.goto end)if "%1" == "json" (%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/jsonif errorlevel 1 exit /b 1echo.echo.Build finished; now you can process the JSON files.goto end)if "%1" == "htmlhelp" (%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelpif errorlevel 1 exit /b 1echo.echo.Build finished; now you can run HTML Help Workshop with the ^.hhp project file in %BUILDDIR%/htmlhelp.goto end)if "%1" == "qthelp" (%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelpif errorlevel 1 exit /b 1echo.echo.Build finished; now you can run "qcollectiongenerator" with the ^.qhcp project file in %BUILDDIR%/qthelp, like this:echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Python-OperSource-Project-Developer-Guide.qhcpecho.To view the help file:echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Python-OperSource-Project-Developer-Guide.ghcgoto end)if "%1" == "devhelp" (%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelpif errorlevel 1 exit /b 1echo.echo.Build finished.goto end)if "%1" == "epub" (%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epubif errorlevel 1 exit /b 1echo.echo.Build finished. The epub file is in %BUILDDIR%/epub.goto end)if "%1" == "latex" (%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latexif errorlevel 1 exit /b 1echo.echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.goto end)if "%1" == "latexpdf" (%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latexcd %BUILDDIR%/latexmake all-pdfcd %~dp0echo.echo.Build finished; the PDF files are in %BUILDDIR%/latex.goto end)if "%1" == "latexpdfja" (%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latexcd %BUILDDIR%/latexmake all-pdf-jacd %~dp0echo.echo.Build finished; the PDF files are in %BUILDDIR%/latex.goto end)if "%1" == "text" (%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/textif errorlevel 1 exit /b 1echo.echo.Build finished. The text files are in %BUILDDIR%/text.goto end)if "%1" == "man" (%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/manif errorlevel 1 exit /b 1echo.echo.Build finished. The manual pages are in %BUILDDIR%/man.goto end)if "%1" == "texinfo" (%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfoif errorlevel 1 exit /b 1echo.echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.goto end)if "%1" == "gettext" (%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/localeif errorlevel 1 exit /b 1echo.echo.Build finished. The message catalogs are in %BUILDDIR%/locale.goto end)if "%1" == "changes" (%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changesif errorlevel 1 exit /b 1echo.echo.The overview file is in %BUILDDIR%/changes.goto end)if "%1" == "linkcheck" (%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheckif errorlevel 1 exit /b 1echo.echo.Link check complete; look for any errors in the above output ^or in %BUILDDIR%/linkcheck/output.txt.goto end)if "%1" == "doctest" (%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctestif errorlevel 1 exit /b 1echo.echo.Testing of doctests in the sources finished, look at the ^results in %BUILDDIR%/doctest/output.txt.goto end)if "%1" == "coverage" (%SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverageif errorlevel 1 exit /b 1echo.echo.Testing of coverage in the sources finished, look at the ^results in %BUILDDIR%/coverage/python.txt.goto end)if "%1" == "xml" (%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xmlif errorlevel 1 exit /b 1echo.echo.Build finished. The XML files are in %BUILDDIR%/xml.goto end)if "%1" == "pseudoxml" (%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxmlif errorlevel 1 exit /b 1echo.echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.goto end):end
支付宝 微信