China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-23 00:13
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Reference for Arrangement] The Role of Symbols under CMD/DOS StickyI View 153,273 Replies 216
Original Poster Posted 2007-05-27 18:29 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
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.

' '
Recent Ratings for This Post ( 27 in total) Click for details
RaterScoreTime
bjsh +20 2007-05-27 19:55
qzwqzw +15 2007-05-27 19:57
zh159 +15 2007-05-27 20:24
qinbuer +2 2007-06-01 02:04
qingfushuan +2 2007-06-01 13:31
vlq5299 +2 2007-06-09 00:52
Billunique +4 2007-09-20 23:08
everest79 +15 2007-10-07 21:49
chhm2123 +1 2007-10-23 11:15
zouzhxi +4 2007-10-31 17:17
zqdarkday +2 2007-11-15 01:34
honghunter +2 2007-12-04 16:41
regvip2008 +2 2007-12-09 11:14
xiaohacker +2 2007-12-23 20:29
kootoo +2 2007-12-25 19:07
haiou327 +4 2008-01-03 19:08
523066680 +8 2008-08-15 20:09
applecy +2 2008-10-04 10:39
taotaomike +1 2008-10-10 12:00
exzzz +2 2009-01-12 14:29
slx8528 +1 2009-02-07 15:34
joyoustar +2 2009-04-08 03:46
shifengl +1 2009-05-21 08:39
zhangwencheng +2 2009-05-29 07:31
kevinm +1 2009-12-03 22:27
hxuan999 +4 2009-12-23 22:19
zzz19760225 +2 2017-10-29 10:32
Floor 2 Posted 2007-05-27 18:51 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Not bad, the format and content are much more complete.

Put forward a few more suggestions (don't blame me for being wordy, please).

Complete the content such as -, >>, <<, +=, etc. according to the content of set /a.

Note that when using!, &, >>, << in set /a, they should be used with ^ or "".

Add the usage of handles in > and <.
Floor 3 Posted 2007-05-27 19:51 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Re qzwqzw:

Hehe, why would I blame? I'm only grateful.

I've added the several ones you mentioned, and randomly added a few others.
Floor 4 Posted 2007-05-27 19:55 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Very Good !!!
Floor 5 Posted 2007-05-28 09:05 ·  中国 湖北 武汉 电信
新手上路
Credits 18
Posts 7
Joined 2007-04-14 04:12
19-year member
UID 85084
Gender Male
Status Offline
Nice article, learning
Floor 6 Posted 2007-05-28 09:13 ·  中国 上海 电信
初级用户
★★
Credits 180
Posts 84
Joined 2006-09-07 00:33
19-year member
UID 61995
Status Offline
Put forward the suggestion again, and also incorporate the things in the prompt.
Floor 7 Posted 2007-05-28 09:15 ·  中国 上海 电信
初级用户
★★
Credits 180
Posts 84
Joined 2006-09-07 00:33
19-year member
UID 61995
Status Offline
There are also things like the :eof in the batch goto statement, the :~ character interception, and the substitution character operation, etc., which can also be regarded as something special. Newcomers find these hard to understand or are relatively easy to ignore.

[ Last edited by ttyp on 2007-5-28 at 09:17 AM ]
Floor 8 Posted 2007-05-28 11:09 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 61
Joined 2007-04-14 09:23
19-year member
UID 85115
Gender Male
Status Offline
Save it and read it later.
Floor 9 Posted 2007-05-28 11:25 ·  中国 江苏 无锡 电信
初级用户
Credits 80
Posts 43
Joined 2007-04-21 23:44
19-year member
UID 86017
Gender Male
Status Offline
Hmm. Rare. Bookmark.
Floor 10 Posted 2007-05-28 14:13 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Re ttyp:

It has been supplemented.

Regarding :EOF, it is actually also a label, but it is a relatively special label, so it is not specifically pointed out.
Floor 11 Posted 2007-05-28 17:11 ·  中国 湖北 武汉 电信
中级用户
★★
scriptlover
Credits 328
Posts 131
Joined 2007-03-25 22:17
19-year member
UID 82910
Gender Male
Status Offline
It's really a good thing, thank you, moderator, for the additional supplement again.
scriptlover
Be with script forever!!
Floor 12 Posted 2007-05-30 22:12 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Originally posted by lxmxn at 2007-5-27 18:29:
Since there are few summaries of DOS symbols, so according to , after several reorganizations, I wrote the following "CMD/DOS Symbol Reference", which is recommended for novices to read carefully and for veterans to review.

Title: ...




Supplement the following:

:: In batch processing, the role is "comment"
For example:

...
:: This is a comment line
...





I haven't been here for a long time.

[ Last edited by scriptor on 2007-5-30 at 10:14 PM ]
Floor 13 Posted 2007-05-30 22:23 ·  中国 北京 联通(数字北京大厦IDC机房)
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
What's the meaning of `goto :eof`?
Floor 14 Posted 2007-05-30 22:24 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Re scriptor:

Well, thanks for the supplement, I'll add it in.

According to the explanation of qzwqze on the 15th floor, the comment description about :: has been canceled.

[ Last edited by lxmxn on 2007-5-31 at 10:17 AM ]
Floor 15 Posted 2007-05-31 00:02 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Comments about ::

I remember someone once said
It's just an invalid tag
Comments are just its side effect

Because when cmd detects an invalid character after a colon, it directly ignores the processing
So a space after a colon can also be used as a comment mark
There are many similar invalid characters
Those who are interested can find them slowly

Also
~ in set/a is bitwise NOT, similar to ^ & |
For example, the binary form of 10 is 00001010
After NOT, it is 11110101
Converted to decimal number is -11
Equivalent to +1 and then take the negative
The statement of opposite number is easy to be misleading

^ is bitwise XOR

[ Last edited by qzwqzw on 2007-5-31 at 12:09 AM ]
1 2 3 15 Next ›
Forum Jump: