Windows批处理文件有哪些不太为人所知,但很重要和有用的特性?
指南:
每个答案一个特征 给出特性的简短描述和示例,而不仅仅是文档链接 将答案限制在本地功能,即不需要额外的软件,如Windows资源包
澄清:这里我们指的是由cmd.exe处理的脚本,这是WinNT变体的默认值。
(请参见:Windows批处理文件:.bat vs .cmd?)
Windows批处理文件有哪些不太为人所知,但很重要和有用的特性?
指南:
每个答案一个特征 给出特性的简短描述和示例,而不仅仅是文档链接 将答案限制在本地功能,即不需要额外的软件,如Windows资源包
澄清:这里我们指的是由cmd.exe处理的脚本,这是WinNT变体的默认值。
(请参见:Windows批处理文件:.bat vs .cmd?)
当前回答
HELP
当使用不同的操作系统版本时,了解本机可用的命令是很重要的。在命令提示符处输入HELP可以显示可用的命令,以及它们的功能的简要描述。
cmd.exe /?
这将列出用于启动命令提示符的所有命令行参数,以及更改整个系统行为的注册表调整。
其他回答
There is also the EDLIN command. While it may be an old bastard tool once used for line-based text editing, the fact that it's controllable from the command line makes it rather useful for batch scripting, mostly because, just like any other case you'd be using EDLIN, it's the only tool available. After all, EDLIN is not a tool you would ordinarily want to use for text editing, unless you are somewhat masochistic. To quote Tim Patterson (the fellow who wrote it): "I was aghast when I heard that IBM was using it and not throwing it out the window."
注意:EDLIN将老式的EOF (1A)标记添加到它编辑的文件中。如果需要删除它们,可能必须使用DEBUG。
我总是发现很难阅读每行用关键字标记的注释:
REM blah blah blah
易于阅读:
:: blah blah blah
子字符串变量:
> set str=0123456789
> echo %str:~0,5%
01234
> echo %str:~-5,5%
56789
> echo %str:~3,-3%
3456
没有提供太多的功能,但是您可以将title命令用于一些用途,比如在任务栏中提供长脚本的状态,或者只是增强用户反馈。
@title Searching for ...
:: processing search
@title preparing search results
:: data processing
整数运算:
> SET /A result=10/3 + 1
4