因关于DOS符号的总结很少,所以根据,经过几次整理之后,写了下面这个《CMD/DOS符号参考》,推荐新手好好看看,老手温习。
标题: CMD/DOS下符号的作用参考
作者:lxmxn bbs.cn-dos.net
时间:2007-5-27
邮箱:lxmxn520163.com
说明:1、转帖请注明原帖出处属于中国DOS联盟(
www.cn-dos.net/forum);
2、欢迎大家补充还未说明到的符号;
3、有任何错误还请不吝指出;
4、特别感谢
qzwqzw 对此资料提出的补充和建议。
正文开始:
__________________________________________________________________________________________
一、单符号
~
① 在for中表示使用增强的变量扩展。
② 在%var:~n,m%中表示使用扩展环境变量指定位置的字符串。
③ 在set/a中表示一元运算符,将操作数按位取反。
!
① 在set /a中一元运算符,表示逻辑非。比如set /a a=!0,这时a就表示逻辑1。
@
① 隐藏命令行本身的回显,常用于批处理中。
$
① 在findstr命令里面表示一行的结束。
② 在prompt命令里面,表示将其后的字符转义(符号化或者效果化)。
%
① 在set /a中的二元运算符,表示算术取余。
② 命令行环境下,在for命令in前,后面接一个字符(可以是字母、数字或者一些特定字符),表示指定一个循环或者遍历指标变量。
③ 批处理中,后接一个数字表示引用本批处理当前执行时的指定的参数。
④ 其它情况下,%将会被脱去(批处理)或保留(命令行)
^
① 取消特定字符的转义作用,比如& | > < ! "等,但不包括%。比如要在屏幕显示一些特殊的字符,比如> >> | ^ &等符号时,就可以在其前面加一个^符号来显示这个^后面的字符了,^^就是显示一个^,^|就是显示一个|字符了;
② 在set/a中的二元运算符,表示按位异或。
③ 在findstr/r的中表示不匹配指定的字符集。
&
① 命令连接字符。比如我要在一行文本上同时执行两个命令,就可以用&命令连接这两个命令。
② 在set/a中是按位与。
*
① 代表任意个任意字符,就是我们通常所说的"通配符";比如想在c盘的根目录查找c盘根目录里所有的文本文件(.txt),那么就可以输入命令"dir c:\*.txt"。
② 在set /a中的二元运算符,表示算术乘法。
③ 在findstr/r中表示将前一个字符多次匹配。
-
① 范围表示符,比如日期的查找,for命令里的tokens操作中就可以用到这个字符。
② 在findstr/r中连接两个字符表示匹配范围。
③ -跟在某些命令的/后表示取反向的开关。
④ 在set /a中:
1.表示一个负数。
2.表示算术减运算。
+
① 主要是在copy命令里面会用到它,表示将很多个文件合并为一个文件,就要用到这个+字符了。
② 在set/a中的二元运算符,表示算术加法。
:
① 标签定位符,表示其后的字符串为以标签,可以作为goto命令的作用对象。比如在批处理文件里面定义了一个":begin"标签,用"goto begin"命令就可以转到":begin"标签后面来执行批处理命令了。
② 在%var:string1=string2%中分隔变量名和被替换字串关系。
|
① 管道符,就是将上一个命令的输出,作为下一个命令的输入."dir /a/b |more"就可以逐屏的显示dir命令所输出的信息。
② 在set/a中的二元运算符,表示按位或。
③ 在帮助文档中表示其前后两个开关、选项或参数是二选一的。
/
① 表示其后的字符(串)是命令的功能开关(选项)。比如"dir /s/b/a-d"表示"dir"命令指定的不同的参数。
② 在set/a中表示除法。
>
① 命令重定向符,将其前面的命令的输出结果重新定向到其后面的设备中去,后面的设备中的内容被覆盖。比如可以用"dir > lxmxn.txt"将"dir"命令的结果输出到"lxmxn.txt"这个文本文件中去。
② 在findstr/r中表示匹配单词的右边界,需要配合转义字符\使用。
<
① 将其后面的文件的内容作为其前面命令的输入。
② 在findstr/r中表示匹配单词的左边界,需要配合转义字符\使用。
=
① 赋值符号,用于变量的赋值。比如"set a=windows"的意思意思是将"windows"这个字符串赋给变量"a"。
② 在set/a中表示算术运算,比如"set /a x=5-6*5"。
\
① 这个"\"符号在有的情况下,代表的是当前路径的根目录.比如当前目录在c:\windows\system32下,那么你"dir \"的话,就相当与"dir c:\"。
② 在findstr/r中表示正则转义字符。
,
① 在set /a中表示连续表达式的分割符。
② 在某些命令中分割元素。
.
① 在路径的\后紧跟或者单独出现时:
一个.表示当前目录。
两个.表示上一级目录。
② 在路径中的文件名中出现时:
最后的一个.表示主文件名与扩展文件名的分隔。
?
① 在findstr/r中表示在此位置匹配一个任意字符。
② 在路径中表示在此位置通配任意一个字符。
③ 紧跟在/后表示获取命令的帮助文档。
__________________________________________________________________________________________
二、多符号(符号不能分隔)
&&
① 连接两个命令,当&&前的命令成功时,才执行&&后的命令。
||
① 连接两个命令,当||前的命令失败时,才执行||后的命令。
>&
① 将一个句柄的输出写入到另一个句柄的输入中。
<&
① 从一个句柄读取输入并将其写入到另一个句柄输出中。
%%
① 两个连续的%表示在预处理中脱为一个%。
② 批处理中,在for语句的in子句之前,连续两个%紧跟一个字符(可以是字母、数字和一些特定字符),表示指定一个循
环或者遍历指标变量。
③ 批处理中,在for语句中,使用与in之前指定的指标变量相同的串,表示引用这个指标变量。
>>
① 命令重定向符,将其前面的命令的输出结果追加到其后面的设备中去。
② 在set /a中的二元运算符,表示逻辑右移。
==
① 在if命令中判断==两边的元素是否相同。
<<
① 在set /a中的二元运算符,表示逻辑左移。
+=
① 在set /a中的二元运算符。例如set /a a+=b表示将a加上b的结果赋值给a。
-=
① 在set /a中的二元运算符。例如set /a a-=b表示将a减去b的结果赋值给a。
*=
① 在set /a中的二元运算符。例如set /a a*=b表示将a乘以b的结果赋值给a。
/=
① 在set /a中的二元运算符。例如set /a a/=b表示将a除以b的结果赋值给a。
%=
① 在set /a中的二元运算符。例如set /a a%=b表示将a除以b的余数赋值给a。
【注:命令行可以直接用 set /a a%=b ,在批处理里面可以用 set /a a%%=b 。】
^=
① 在set /a中的二元运算符。例如set /a a"^="b表示将a与b按位异的结果赋值给a。
【注:这里 "^=" 加引号是为了防止^被转义,下同。】
&=
① 在set /a中的二元运算符。例如set /a a"&="b表示将a与b按位与的结果赋值给a。
|=
① 在set /a中的二元运算符。例如set /a a"|="b表示将a与b按位或的结果赋值给a。
<<=
① 在set /a中的二元运算符。例如set /a a"<<="b表示将a按位左移b位的结果赋值给a。
>>=
① 在set /a中的二元运算符。例如set /a a">>="b表示将a按位右移b位的结果赋值给a。
\<
① 在findstr的一般表达式中表示字的开始处。
\>
① 在findstr的一般表达式中表示字的结束处。
__________________________________________________________________________________________
三、双符号对(两个符号之间须指定字符串)
! !
① 当启用变量延迟时,使用!!将变量名扩起来表示对变量值的引用。
' '
① 在for/f中表示将它们包含的内容当作命令行执行并分析其输出。
② 在for/f "usebackq"中表示将它们包含的字符串当作字符串分析。
( )
① 命令包含或者是具有优先权的界定符,比如for命令要用到这个(),我们还可以在if,echo等命令中见到它的身影。
② 在set /a中表示表达式分组。
" "
① 界定符,在表示带有空格的路径时常要用""来将路径括起来,在一些命令里面也需要" "符号。
② 在for/f中将表示它们包含的内容当作字符串分析。
③ 在for/f "usebackq"表示它们包含的内容当作文件路径并分析其文件的内容。
④ 在其它情况下表示其中的内容是一个完整的字符串,其中的>、>>、<、&、|、空格等不再转义。
` `
① 在for/f中表示它们所包含的内容当作命令行执行并分析它的输出。
% %
① 使用两个单独的%包含一个字符串表示引用以此串为名的环境变量。比如一个%time%可以扩展到当前的系统时间。
① 在帮助文档表示其中的开关、选项或参数是可选的。
② 在findstr /r中表示按其中指定的字符集匹配。
__________________________________________________________________________________________
参考连接
(4楼)http://www.cn-dos.net/forum/viewthread.php?tid=24289&fpage=1
修改日期
第 1 次补充资料于2006.10.30.
第 2 次补充资料于2006.11.08.
第 3 次补充资料于2006.01.24.
第 4 次补充资料于2007.03.13.
第 5 次补充资料于2007.05.27.
Last edited by lxmxn on 2008-8-25 at 09:53 AM ]
Because there are few summaries of DOS symbols, so according to , after several arrangements, the following "CMD/DOS Symbol Reference" is written. It is recommended that beginners take a good look and veterans review.
Title: Role Reference of Symbols under CMD/DOS
Author: lxmxn bbs.cn-dos.net
Time: 2007-5-27
Email: lxmxn520163.com
Instructions: 1. Please indicate the original post source belonging to the China DOS Union (
www.cn-dos.net/forum) when reposting;
2. Everyone is welcome to supplement the symbols not explained yet;
3. Please feel free to point out any errors;
4. Special thanks to
qzwqzw for the supplements and suggestions to this material.
Start of the main text:
__________________________________________________________________________________________
I. Single Symbols
~
① In for, it means using enhanced variable expansion.
② In %var:~n,m%, it means using the string at the specified position of the expanded environment variable.
③ In set/a, it means the unary operator, bitwise negation of the operand.
!
① In set /a, the unary operator means logical NOT. For example, set /a a=!0, then a represents logical 1.
@
① Hides the echo of the command line itself, often used in batch processing.
$
① In the findstr command, it means the end of a line.
② In the prompt command, it means escaping the characters after it (symbolizing or effectuating).
%
① In set /a, the binary operator means arithmetic remainder.
② In the command line environment, before in in the for command, a character (can be a letter, number or some specific characters) is followed, indicating specifying a loop or traversal index variable.
③ In batch processing, a number is followed to represent referring to the specified parameter when the current batch processing is executed.
④ In other cases, % will be stripped (batch processing) or retained (command line)
^
① Cancels the escape function of a specific character, such as & | > < ! " etc., but not including %. For example, to display some special characters on the screen, such as > >> | ^ & and other symbols, you can add a ^ symbol in front of them to display the character after this ^; ^^ is to display a ^, ^| is to display a | character;
② In set/a, the binary operator means bitwise XOR.
③ In of findstr/r, it means not matching the specified character set.
&
① Command connection character. For example, if I want to execute two commands on one line of text, I can use the & command to connect these two commands.
② In set/a, it is bitwise AND.
*
① Represents any number of any characters, which is the so-called "wildcard"; for example, if you want to find all text files (.txt) in the root directory of the C drive, you can enter the command "dir c:\*.txt".
② In set /a, the binary operator means arithmetic multiplication.
③ In findstr/r, it means matching the previous character multiple times.
-
① Range identifier, for example, in date lookup, it can be used in the tokens operation in the for command.
② In findstr/r, connect two characters to represent matching range.
③ - followed after / of some commands means taking the reverse switch.
④ In set /a:
1. Represents a negative number.
2. Represents arithmetic subtraction operation.
+
① Mainly used in the copy command, it means combining many files into one file, and this + character is needed.
② In set/a, the binary operator means arithmetic addition.
:
① Label locator, indicates that the following string is a label, which can be the object of the goto command. For example, a ":begin" label is defined in the batch file, and the "goto begin" command can be used to go to the ":begin" label to execute the batch command.
② In %var:string1=string2%, separates the relationship between the variable name and the replaced string.
|
① Pipe character, which takes the output of the previous command as the input of the next command. "dir /a/b |more" can display the information output by the dir command screen by screen.
② In set/a, the binary operator means bitwise OR.
③ In the help document, it means that the two switches, options or parameters before and after it are optional.
/
① Represents that the following character (string) is the function switch (option) of the command. For example, "dir /s/b/a-d" means different parameters specified by the "dir" command.
② In set/a, it means division.
>
① Command redirection character, redirects the output result of the previous command to the device behind it, and the content in the following device is overwritten. For example, you can use "dir > lxmxn.txt" to output the result of the "dir" command to the text file "lxmxn.txt".
② In findstr/r, it means matching the right boundary of the word, and needs to be used with the escape character \.
<
① Takes the content of the file behind it as the input of the previous command.
② In findstr/r, it means matching the left boundary of the word, and needs to be used with the escape character \.
=
① Assignment symbol, used for variable assignment. For example, "set a=windows" means assigning the string "windows" to the variable "a".
② In set/a, it means arithmetic operation, for example, "set /a x=5-6*5".
\
① This "\" symbol in some cases represents the root directory of the current path. For example, if the current directory is under c:\windows\system32, then "dir \" is equivalent to "dir c:\".
② In findstr/r, it means the regular escape character.
,
① In set /a, it means the separator of consecutive expressions.
② In some commands, it separates elements.
.
① When following \ in the path or appearing alone:
One. represents the current directory.
Two.. represents the upper-level directory.
② When appearing in the file name in the path:
The last. represents the separator between the main file name and the extension file name.
?
① In findstr/r, it means matching any character at this position.
② In the path, it means matching any character at this position.
③ Followed after / means getting the help document of the command.
__________________________________________________________________________________________
II. Multi-symbols (symbols cannot be separated)
&&
① Connect two commands, and the command after && is executed only when the command before && is successful.
||
① Connect two commands, and the command after || is executed only when the command before || fails.
>&
① Writes the output of one handle to the input of another handle.
<&
① Reads input from one handle and writes it to the output of another handle.
%%
① Two consecutive % mean to be stripped to one % during preprocessing.
② In batch processing, before the in clause of the for statement, two consecutive % follow a character (can be a letter, number and some specific characters), indicating specifying a loop or traversal index variable.
③ In batch processing, in the for statement, use the same string as the index variable specified before in, indicating referring to this index variable.
>>
① Command redirection character, appends the output result of the previous command to the device behind it.
② In set /a, the binary operator means logical right shift.
==
① In the if command, judge whether the elements on both sides of == are the same.
<<
① In set /a, the binary operator means logical left shift.
+=
① In set /a, the binary operator. For example, set /a a+=b means assigning the result of a plus b to a.
-=
① In set /a, the binary operator. For example, set /a a-=b means assigning the result of a minus b to a.
*=
① In set /a, the binary operator. For example, set /a a*=b means assigning the result of a multiplied by b to a.
/=
① In set /a, the binary operator. For example, set /a a/=b means assigning the result of a divided by b to a.
%=
① In set /a, the binary operator. For example, set /a a%=b means assigning the remainder of a divided by b to a.
【Note: The command line can directly use set /a a%=b, and in batch processing, you can use set /a a%%=b.】
^=
① In set /a, the binary operator. For example, set /a a"^="b means assigning the result of a bitwise XOR with b to a.
【Note: Here, "^=" is quoted to prevent ^ from being escaped, the same below.】
&=
① In set /a, the binary operator. For example, set /a a"&="b means assigning the result of a bitwise AND with b to a.
|=
① In set /a, the binary operator. For example, set /a a"|="b means assigning the result of a bitwise OR with b to a.
<<=
① In set /a, the binary operator. For example, set /a a"<<="b means assigning the result of a bitwise left shift by b bits to a.
>>=
① In set /a, the binary operator. For example, set /a a">>="b means assigning the result of a bitwise right shift by b bits to a.
\<
① In the general expression of findstr, it means the beginning of a word.
\>
① In the general expression of findstr, it means the end of a word.
__________________________________________________________________________________________
III. Double-symbol pairs (two symbols must specify a string between them)
! !
① When variable delay is enabled, use!! to enclose the variable name to represent the reference to the variable value.
' '