Since the person upstairs said so, I'll post the functions of general symbols. You can take a good look. Actually, they are in the forum....
Your question is related to two elements:
1. % is an ESCAPE character, usually translated as an escape character, but there are more vivid translations like escape character, evasion character, etc. That is to say, % not only escapes the specific string related to it and replaces it with a specific string, but also itself will be "escaped". And similar to the escape character "\" in the C language, double % will be escaped and escaped to single %, and four % will be escaped to double %.
2. for itself is a special command, similar to a specialized command interpreter. Because its function implementation requires executing multiple statements, it must also have the function of analyzing and processing the command line (specifically, the command line after do). And when command/cmd implements for, it will naturally borrow its own original command line analysis module. Therefore, for has the characteristic of secondary escape. The statement after do in for is analyzed and interpreted in two levels. The first level is when command/cmd reads and interprets the for command line, and the second level is when for reads and interprets the do command. It usually interprets the same command line multiple times.
Then, we can notice that when using command line parameter variables and environment variables in do, double % are not needed. That is because these variables are replaced with specific constant strings after the first level of escape, and participate in all execution processes of the for loop; while the replacement variables require dynamic changes during execution (in the sub-command line after do), and this change naturally still needs to be realized through the escape character. Therefore, the use of double % becomes a necessity.
In addition, it should also be noted that when using for in the command line, double % are not needed. This stems from the different processing methods of the command interpreter for the command line and the batch processing. In the early DOS versions, % was not regarded as an escape character in the command line, so it would not be escaped and escaped. Therefore, at that time, it was impossible to directly reference environment variables in the command line. And when using for, only one % is needed for for to perform escape and escape. In the later versions of the command interpreter, support for command line escape (mainly support for environment variables) was added, but the tradition of using single % for command line for has been retained.
And the variable delayed expansion in cmd is a special case, but it does not violate the above escape principles. It's just that the environment variables in for are no longer constants.
rmdir /S /Q %mhnet% 2>NUL 1>NUL is simply explained
The general meaning of this code is to delete the directory specified by %mhnet%. /s means to delete the subdirectories in it. /q means not to prompt for confirmation when deleting the directory tree. 1>nul means to prohibit outputting the information of correctly deleting the directory tree. 2>nul means to prohibit outputting the error information during the deletion process
Among them, 1 and 2 are both representing the address of a certain data flow input and output (NT CMD calls it a handle, MSDOS calls it a device). The following table (quoted from the "Using Command Redirection Operators (Redirection Operators" section of the WinXP help document) will list the available handles.
Handle Handle number code Description
STDIN 0 Keyboard input
STDOUT 1 Output to the command prompt window
STDERR 2 Error output to the command prompt window
UNDEFINED 3-9 These handles are individually defined by applications and various specific tools
0 Keyboard input
1 Output to the command prompt window
2 Error output to the command prompt window
3-9 These handles are individually defined by applications and various specific tools.
2 > nul means that the information of the program error is not displayed.
call attrib -r -h c:\autoexec.bat >nul
In fact, this is:
call attrib -r -h c:\autoexec.bat 1 > nul
These 1, 2, 0, etc. are all handles. To put it simply, you just need to know that 1 represents the output information, 2 represents the error information, and 0 represents the keyboard input.
If you don't understand anything, you can read more help and support.
The command line does not make excessive restrictions on the position where the redirection symbol appears. As long as the redirection symbol is immediately followed by a "character device", the following statements are equivalent:
echo Hello World> hello.txt
echo Hello> Hello.txt World
echo> Hello.txt Hello World
> hello.txt echo Hello World
In the NT series command line, the scope of the redirection changes from the entire command line to a single command statement, and is restricted by the command separators &, &&, || and statement blocks.
echo Message1> msg1.txt & echo Message2> msg2.txt
if "%target%"=="" (echo message to screen ) else (echo message to file> %target%)
In summary, >nul means to redirect the standard output request generated by this command to the null device. And because of the silent characteristic of this device, it is equivalent to shielding the output information of this statement (not hiding it); and 2>nul is to redirect and shield the standard error information output request when the program executes in error. When used together, it means shielding all possible output information of this statement.
"Redirection" is a command line feature that has existed since MSDOS. It is responsible for redirecting the input and output requests of the specified command or statement from the default "console" to other "devices" to complete. Its start mark is that the "redirection symbol" (including ">", ">>", "<" three, their respective meanings are in [1]) appears in the sentence.
Generally, the input and output requests of command line programs are completed through three internally defined "ports" (called "handles" in NT, not defined in DOS), namely standard input stdin, standard output stdout, and standard error stderr. The devices they usually point to are the console (console, code is CON). Among them, stdin points to the keyboard of the console, and stdout/stderr points to the monitor of the console. Therefore, the console usually refers to the combination of the keyboard and the monitor, which is the concept reflected on the terminal of the early mainframe. Among them, stdin can be redirected by <, stdout can be redirected by >, >>, and stderr cannot be directly redirected in DOS. Only by transferring the system control to other devices through commands such as ctty or other commands can it be indirectly completed.
"Device" refers to a device driver or port code that can control PC hardware or ports. It is usually implemented and supported by the system bottom layer or hardware driver. For example, CON, CLOCK$ implemented by IO.SYS, CONFIG$ unknown device, first serial port AUX, first parallel port PRN, all serial ports COM1~COM4, all parallel ports LPT1~LPT3, available drive letters A:-X: and the null device NUL mentioned above. There are many other devices, such as XMSXXXX0 implemented by HIMEM.SYS, EMMXXXX0 implemented by EMM386.EXE, IFS$HLP$ implemented by IFSHLP.SYS, etc.
Among these devices, there are few that can process input and output information. Only the CON, NUL, and serial or parallel port devices connected with input and output hardware (printers, MODEM, etc.). They are called "character devices", and disk files are also listed as a special character device, which greatly expands the freedom and practicability of redirection, so many people also call redirection "file redirection".
The null device NUL is a special device. Because it has no controllable PC hardware or port, but is just a fictional device or port, it only exists at the software level. Because of this, it can accept all redirected input and output requests without giving any response (in NT, it will end the input request without giving any input information, and in DOS, it will repeatedly fill 127 bytes 0 and then terminate the response). This characteristic makes it very much like a "black hole" in astronomy that can devour all matter and information, and is also very similar to the "mysterious way" in philosophy that can reverse yin and yang and generate from nothing. It exists because we need a "recycling bin" that can unconditionally absorb various redundant output information or input requests silently, just as the "black hole" is like a huge "cosmic garbage dump".
CMD is not neurotic. It's that the integer processed by set is too large. set uses two-byte storage for integers and has a 32-bit storage range limit. That is to say, its processing range is 2^-31~2^31-1. Your disk space exceeds this range and overflows.
I don't have a very good solution for this. I can only use an approximate algorithm of discarding the last three digits and then dividing by 1049.
for /f "tokens=3" %%a in ('dir /-c c:\^|find "available bytes"') do set freesize=%%a
set /a freesize=%freesize:~0,-3%/1049>nul
echo Freesize:%freesize%
> Create a file
>> Append to the back of a file
@ Prefix character. Indicates that this line is not displayed in cmd when executing. You can use echo off to turn off the 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)
, and space are the default delimiters.
; Comment, indicating that the following is a comment
: Label function
│ Pipe operation
; When the commands are the same, you can separate different targets with ;, but the execution effect remains the same. If an error occurs during the execution process, only the error report is returned, but the program will continue to execute
First of all, @ is not a command, but a special marker in DOS batch processing, only used to shield the command line echo. The following are some special markers that may be seen in the DOS command line or batch processing:
CR(0D) Command line end character
Escape(1B) ANSI escape character guide character
Space(20) Common parameter delimiter
Tab(09) ; = Uncommon parameter delimiter
+ COPY command file connection character
*? File wildcard
"" String delimiter
| Command pipe character
< > >> File redirection character
@ Command line echo shielding character
/ Parameter switch guide character
: Batch processing label guide character
% Batch processing variable guide character
Secondly, :: can indeed play the role of rem comment, and it is more concise and effective; but there are two points to note:
First, except for ::, any character line starting with : is regarded as a label in batch processing, and the content after it is directly ignored. Just to distinguish it from normal labels, it is recommended to use a special symbol that cannot be recognized by goto, that is, a special symbol other than letters and numbers immediately after :.
Second, different from rem, the character line after :: will not be echoed during execution, no matter whether the command line echo state is turned on by echo on or not, because the command interpreter does not think it is a valid command line. In this regard, rem will be more applicable than :: in some occasions; in addition, rem can be used in the config.sys file.
The following usage can also be used:
if exist command
device refers to the device loaded in the DOS system. In win98, there are usually:
AUX, PRN, CON, NUL
COM1, COM2, COM3, COM4
LPT1, LPT2, LPT3, LPT4
XMSXXXX0, EMMXXXX0
A: B: C: ...,
CLOCK$, CONFIG$, DblBuff$, IFS$HLP$
The specific content will be slightly different due to different hardware and software environments. When using these device names, the following three points need to be ensured:
1. The device really exists (except for software virtual devices)
2. The device driver has been loaded (standard devices such as aux, prn are defined by the system by default)
3. The device is ready (mainly refers to a: b: ..., com1..., lpt1...)
You can use the command mem/d | find "device" /i to check the devices loaded in your system
In addition, in the DOS system, the device is also considered a special file, and the file can also be called a character device; because the device (device) and the file are both managed by handles (handle), the handle is the name, similar to the file name. The difference is that the handle is not applied to disk management, but to memory management. The so-called device loading also means allocating a referenceable handle for it in memory.
That should be enough. For why the % symbol is used in the form of %% in batch processing, it is determined by the characteristics of batch processing and commands!!! I hope these can help you...........
Recent Ratings for This Post
( 12 in total)
Click for details