如果要学写批处理命令和msysgit及命令?~
最近安装了mingw和gcc编译器,然后学用bat写msysgit命令对编译文件学件一件运行程序其中包括对编译文件的管理……一些简单的cmd命令还好,不过接触到一些msys的命令例如ls cut之类的就感觉自己小白一个了,就连最基础的语法也不会
主要有以下两点问题:
1--
例如下面一段批处理代码是启动msysgit的,感觉自己现在能力有限看不懂具体内容,虽然有rem注释参考~
程序代码:
@echo off @setlocal rem Copyright (C): 2001, 2002 Earnie Boyd rem mailto:earnie@users. This file is part of Minimal SYStem rem http://www. rem rem File: msys.bat rem Revision: 2.0 rem Revision Date: April 17th, 2002 rem ember to set the "Start in:" field of the shortcut. rem A value similar to C:\msys\1.0\bin is what the "Start in:" field needs rem to represent. rem this should let run MSYS shell on x64 if "%PROCESSOR_ARCHITECTURE%" == "AMD64" ( SET COMSPEC=%WINDIR%\SysWOW64\cmd.exe ) rem ember value of GOTO: is used to know recursion has happened. if "%1" == "GOTO:" goto %2 rem ember only uses the first eight characters of the label. set OS_VERSION="NT" goto _WindowsNT rem ember that we only execute here if we are in OS_VERSION="9x" if "x%COMSPEC%" == "x" set COMSPEC= %COMSPEC% /e:4096 /c %0 GOTO: _Resume %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 goto EOF rem ember that we execute here if we recursed. :_Resume for %%F in (1 2 3) do shift rem ember that we get here even in if "x%MSYSTEM%" == "x" set MSYSTEM=MINGW32 if "%1" == "MSYS" set MSYSTEM=MSYS if NOT "x%DISPLAY%" == "x" set DISPLAY= rem We here assume old behavior, to make sure that older platforms can still use rem this batch file to start their MSys environment. set BIN="" if EXIST bin\nul set BIN=bin\ if EXIST %BIN%bash.exe goto startbash if EXIST %BIN%rxvt.exe goto startrxvt rem If we're not on win9x type OSs, lets try a little better at finding bash/rxvt if "win%OS_VERSION%"=="win9x" goto failed set BIN="%~dp0bin\" if EXIST %BIN%bash.exe goto startbash if EXIST %BIN%rxvt.exe goto startrxvt :failed echo Cannot find the rxvt.exe or bash.exe binary -- aborting. pause rem exit 1 rem we skip using exit 1 here, since it will close the console you were working on rem which probably isn't what you wanted. If the bat file was run from a shortcut rem the window will still close, like you would expect it to. Sorry, you cant test rem for exit values anymore, but hey, you can just un-rem the line above then! :-) goto EOF rem If you don't want to use rxvt then rename the file rxvt.exe to something rem else. Then bash.exe will be used instead. :startrxvt rem Setup the default colors for rxvt. if "x%MSYSBGCOLOR%" == "x" set MSYSBGCOLOR=White if "x%MSYSFGCOLOR%" == "x" set MSYSFGCOLOR=Black if "x%MINGW32BGCOLOR%" == "x" set MINGW32BGCOLOR=LightYellow if "x%MINGW32FGCOLOR%" == "x" set MINGW32FGCOLOR=Navy if "%MSYSTEM%" == "MSYS" set BGCOLOR=%MSYSBGCOLOR% if "%MSYSTEM%" == "MSYS" set FGCOLOR=%MSYSFGCOLOR% if "%MSYSTEM%" == "MINGW32" set BGCOLOR=%MINGW32BGCOLOR% if "%MSYSTEM%" == "MINGW32" set FGCOLOR=%MINGW32FGCOLOR% start %COMSPEC% /c %BIN%rxvt -backspacekey -sl 2500 -fg %FGCOLOR% -bg %BGCOLOR% -sr -fn Courier-12 -tn msys -geometry 80x25 -e /bin/bash --login -i exit :startbash call %COMSPEC% /c %BIN%bash --login -i rem cmd默认情况用执行msys命令不支持中文--把这个的快捷方式复制到运行文件目录下--上面语句可以通过重定向向文本写入程序,等于间接执行msysgit命令(使用者注) :EOF rem ChangeLog: rem 2002.03.07 Earnie Boyd mailto:earnie@users. * Move the @echo off to the top. rem * Change the binmode setting to nobinmode. rem * Remove the angle brackets around email address to workaround MS rem buggy command processor. rem rem 2002.03.12 Earnie Boyd mailto:earnie@users. * Add filter logic to find rxvt.exe rem rem 2002.03.13 Earnie Boyd mailto:earnie@users. * Revert the nobinmode change. rem rem 2002.03.20 Earnie Boyd mailto:earnie@users.* Add logic for stating bash. rem rem 2002.04.11 Earnie Boyd mailto;earnie@users. * Add logic for setting MSYSTEM value based on parameter. rem rem 2002.04.15 Olivier Gautherot mailto:olivier_gautherot@ * Reduce number test conditions for finding an executable. rem rem 2002.04.15 Earnie Boyd mailto:earnie@users. * Unset DISPLAY if set before starting shell. rem rem 2002.04.16 Earnie Boyd mailto:earnie@users. * Remove use of DEFINED in conditional statments for variables for rem support. rem * Add check for nonexistance of USERNAME variable for Win9x support. rem rem 2002.04.17 Earnie Boyd mailto:earnie@users. * Add foreground and background color defaults based on MSYSTEM value. rem rem 2002.04.22 Earnie Boyd mailto:earnie@users. * More Win 9x changes. rem rem 2002.05.04 Earnie Boyd mailto:earnie@users. * Remove the SET of USERNAME and HOME. rem rem 2002.11.18 Earnie Boyd mailto:earnie@users. * Add detection and restart with a larger environment to rem avoid errors on w9x. rem Many thanks to Randy W. Sims mailto:RandyS@ See Randy's response to "RE: [Mingw-msys] Installation on WindowsME" rem from 11/06/2002 in the archives of mingw-msys@lists. 2002.11.19 Paul Garceau mailto:pgarceau@ * Fix a typo: Change COMPSPEC to COMSPEC. rem rem 2002.11.25 Earnie Boyd mailto:earnie@users. * Remove the SET CYGWIN since it doesn't matter any longer. rem rem 2003.02.03 Earnie Boyd mailto:earnie@users. * Win9x doesn't like ``EXISTS dir'' so change it to ``EXISTS dir\nul''. rem Thanks to Nicolas Weber mailto:nicolasweber@gmx.de. rem rem 2003.03.06 Earnie Boyd mailto:earnie@users. * Add -backspacekey switch to rxvt startup. rem * Move RXVT color setup to startrxvt label rem rem 2004.01.30 Earnie Boyd mailto:earnie@users. * Add -geometry parameter to work around an off by one issue with rem the default values. rem Thanks to Dave Schuyler mailto:parameter@users.
再例如找了个获取相对路径的以及列出文件上级路径及名称的:
程序代码:
@echo off setlocal EnableDelayedExpansion echo 当前正在运行的批处理文件所在路径:!cd! @echo off echo 当前目录是:%cd% @echo off :: set "abc=%cd%" echo 当前正在运行的批处理文件所在路径:%~dp0 @echo off echo 当前的盘符及路径:%~dp0 echo 当前的盘符及路径的短文件名格式:%~sdp0 @echo 取当前文件的上级目录的名称 set a=D:\abc\def ghi\j k\lmn.bat for %%a in ("%a%") do ( set ok=%%~dpa for /f "delims=" %%b in ("!ok:~0,-1!") do ( echo %%~nb ) ) pause
bat命令上网搜搜我可以学学,不过如果要学得详细一点应该参考哪些书籍或者有没有什么好的建议?
2--
msysgit命令上网搜过好像讲得简略,几乎没有什么涉及到具体操作的内容或者还是我能力问题搜不到具体的学习方法……
就算有也是直接是应用代码几乎找不到学习语法,如果要系统学习相关内容应该参考哪些书籍或者有哪些好的建议,拜谢了~
最后如果觉得该内容已经超出本版块的讨论范围的,请版主及时转移该帖子到合理的版块,再次感谢~