These are all the basic functions of symbols in cmd, maybe they'll be useful to you
By using conditional processing symbols, you can run multiple commands from a single command line or script. When multiple commands are run through conditional processing symbols, the command to the right of the conditional processing symbol works according to the result of the command to the left of the conditional processing symbol. For example, you may want to run a new command only if the previous command failed. Or, you may want to run a new command only if the previous command succeeded.
You can use the special characters listed in the table below to pass multiple commands.
Character Syntax Definition
& [...] command1 & command2 Used to separate multiple commands on one command line. Cmd.exe runs the first command, then runs the second command.
&& [...] command1 && command2 Used to run the command after the && symbol only if the command before the && symbol succeeds. Cmd.exe runs the first command, and then runs the second command only if the first command ran successfully.
|| [...] command1 || command2 Used to run the command after the || symbol only if the command before the || symbol fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not run successfully (received an error code greater than zero).
( ) [...] (command1 & command2) Used to group or nest multiple commands.
; 或者 , command1 parameter1;parameter2 Used to separate command parameters.
Note
· The ampersand (&), pipe symbol (|), and parentheses () are special characters. If you pass them as parameters, you must put an escape character (^) or quotation marks before them.
· If a command completes successfully, it returns a zero (0) exit code or returns no exit code at all
> create a file
>> append to the end of a file
@ prefix character. Means that when executing, this line is not displayed in cmd; you can use echo off to turn off display
^ leading character for special symbols ( > < &). The first one just displays aaa, the second one outputs to file bbb
echo 123456 ^> aaa
echo 1231231 > bbb
() contains commands
(echo aa & echo bb)
, default separator symbol, same as a space.
; comment, means what follows is a comment
: label function
│ pipe operation
; when the command is the same, this symbol can separate different targets with ; but the execution result does not change. If an error occurs during execution, it only returns an error report but the program will still continue executing
First of all, @ is not a command, but a special marker in DOS batch processing, used only to suppress command-line echo. Below are some special markers you may see in the DOS command line or in batch processing:
CR(0D) command line terminator
Escape(1B) ANSI escape character introducer
Space(20) commonly used parameter delimiter
Tab(09) ; = uncommon parameter delimiters
+ COPY command file concatenation symbol
* ? file wildcards
"" string delimiter
| command pipe symbol
< > >> file redirection symbols
@ command-line echo suppression symbol
/ parameter switch introducer
: batch label introducer
% batch variable introducer
Second, :: can indeed serve as a rem comment, and is more concise and effective; but there are two points to note:
First, besides ::, any line beginning with : is treated as a label in batch processing, and everything after it is directly ignored. Just to distinguish it from a normal label, it is recommended to use a label that goto cannot recognize, that is, put a non-alphanumeric special symbol immediately after :.
Second, unlike rem, a line after :: will not be echoed during execution no matter whether command-line echo is turned on with echo on, because the command interpreter does not regard it as a valid command line. From this point of view, rem is more suitable than :: in some situations; in addition, rem can be used in config.sys files.
The following usage can also be used:
if exist command
device refers to devices that have been loaded in the DOS system; under win98 these usually include:
AUX, PRN, CON, NUL
COM1, COM2, COM3, COM4
LPT1, LPT2, LPT3, LPT4
XMSXXXX0, EMMXXXX0
A: B: C: ...,
CLOCK$, CONFIG$, DblBuff$, IFS$HLP$
The specific contents will vary slightly depending on the hardware and software environment. When using these device names, the following three points must be ensured:
1. The device really exists (except for devices virtualized by software)
2. The device driver has been loaded (standard devices such as aux, prn, etc. are defined by the system by default)
3. The device is ready (mainly refers to a: b: ..., com1..., lpt1..., etc.)
You can use the command mem/d | find "device" /i to inspect the devices loaded in your system
Also, in DOS systems, devices are also regarded as a kind of special file, and files can also be called character devices; because both devices and files are managed by handles, and a handle is the name, similar to a filename, except that a handle is not used for disk management, but for memory management. So-called device loading means allocating a referable handle for it in memory.