In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "which special symbols are commonly used in batch processing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Special symbols commonly used in batch processing
1. @ command line echo mask
2.% batch variable leader
3. > redirector
4, > > redirector
5. &, redirector
Output redirect command
This character means to pass and overwrite, and its role is to pass the result of the run to the following scope (either a file or the default system console).
In the NT series command line, the scope of redirection changes from the entire command line to a single command statement, which is restricted by the command separator &, & &, | | and statement blocks.
For example:
Use the command: echo hello > 1.txt to create the file 1.txt with the content "hello" (notice a space at the end of the line)
Use the command: echo hello > 1.txt to create the file 1.txt with the content "hello" (note that there is no space at the end of the line)
4, > > redirector
Output redirect command
The function of this symbol is somewhat similar to >, but the difference is that > > is passed and appended at the end of the file, while > is overridden.
Usage is the same as above
Also take 1.txt as an example.
Use the command:
Echo hello > 1.txtecho world > > 1.txt
At this point, the 1.txt content is as follows:
Hello
World
5. &, nul means to prohibit the output of correct information
2 > nul means that the output of error messages is prohibited.
Where 1 and 2 are addresses that represent the input and output of a data stream (NT CMD calls it a handle and MSDOS calls it a device).
Handle 0: standard input stdin, keyboard input
Handle 1: standard output stdout, output to the command prompt window (console, code CON)
Handle 2: standard error stderr, output to the command prompt window (console, code CON)
The stdin can be redirected by >.
We already know that you can use the for command to read the contents of the text, but it's a bit troublesome to use the for command if you only need to read the first line. The simple solution is as follows:
@ echo offset / p str=1.txt
The result is: test > 1.txt
He didn't add it to 1.txt, hehe. It just shows it.
In addition, this escape character can also be used as a continuation symbol.
Take a simple example:
@ echo offecho hero ^ is ^ good ^ man pause
Needless to say, you'll see if you try it yourself.
Why does an escape character act as a continuation character at the end of a line? The reason is simple, because there is an invisible symbol at the end of each line, the carriage return, which is invalidated when the escape character is at the end of the line, thus continuing the line.
8. & combine commands
Syntax: the first command & the second command [& the third command.]
&, & &, | | is a combined command, which, as the name implies, can be executed by combining multiple commands into a single command. This is allowed in batch scripts and is widely used. Because the batch process does not recognize the number of commands.
This symbol allows you to use more than two different commands on one line, and when the first command fails, it does not affect the execution of subsequent commands.
Here & the commands on both sides are executed sequentially, from the back.
For example:
Dir z:\ & dir y:\ & dir c:\
The above command will continuously display the contents of disk zMY and c, regardless of whether the disk exists.
9. & & combination command
Syntax: the first command & the second command [& & the third command.]
In this way, multiple commands can be executed at the same time. When there is an error in the execution of the command, the subsequent command will not be executed, and all the commands will be executed all the time if there has been no error.
This command is similar to the one above, but the difference is that when the first command fails, the later command will not be executed
Dir z:\ & & dir y:\ & & dir c:\
10. | | combine commands
Syntax: first command | | second command [| | third command.]
In this way, multiple commands can be executed at the same time. When one command fails, the second command is executed. When the correct command is executed, the subsequent command will not be executed. If there is no correct command, all the commands will be executed all the time.
Tip: priority must be paid to when using the combined command with the redirect command.
Pipe commands take precedence over redirect commands, and redirect commands take precedence over combined commands.
Problem: list the files and folders of disk C and disk D in the a.txt file. Look at the example:
Dir c:\ & & dir d:\ > a.txt
After this execution, there is only D disk information in the a.txt! Why? Because the priority of the combined command is not as high as that of the redirect command! So this sentence divides the line into two parts: dir c:\ and dir d:\ > a.txt, not as you might think: dir c:\ & & dir d:\ and > a.txt. To use the combined command & & to meet the requirements of the title, you must write:
Dir c:\ > a.txt & & dir d:\ > a.txt
In this way, according to the priority, DOS will divide the sentence into the following two parts: dir c:\ > a.txt and dir d:\ > a.txt. The difference of a few sentences in example 18 is quite special and is worth studying and understanding.
Of course, you can also use the command here (think for yourself):
Dir c:\ > a.txt & dir d:\ > a.txt
[this can also be implemented with dir c:\; d:\ > > a.txt]
11. "string delimiter"
Double quotation marks allow you to include spaces in a string, and you can enter a special directory in the following ways
Cd "program files"
Cd progra~1
Cd pro*
The above three methods can be entered into the program files directory
12. Comma
Commas are equivalent to spaces, and in some cases "," can be used as spaces to make
such as
Dir,c:\
13; semicolon
Semicolon, when the command is the same, different targets can be used to isolate, but the execution effect remains the same. If an error occurs during execution, only an error report is returned, but the program will still execute. (some people say that they will not continue to execute, but in fact, you will know after a test.)
For example:
Dir c:\; d:\; e:\; z:\
The above command is equivalent to
Dir c:\
Dir d:\
Dir e:\
Dir f:\
If the z disk does not exist, the run shows that the system cannot find the specified path. Then terminate the execution of the command.
Example: dir c:\; d:\; e:\ 1.txt
The above command is equivalent to
Dir c:\
Dir d:\
Dir e:\ 1.txt
The file e:\ 1.txt does not exist, but the e disk exists and there is an error prompt, but the command will still be executed.
Why? If the destination path does not exist, execution is terminated; if the path exists and only the file does not exist, execution continues.
That's all! If you have any comments, please reply! If you have any questions, please go to the BAT communication area to post! The next section is improved!
14. () brackets
Parentheses play a special role in batch programming, the left and right parentheses must be used in pairs, and the parentheses can include multiple lines of commands, which are treated as a whole and as a command line.
Parentheses are common in for and if statements and are used to nest loops or conditional statements. In fact, parentheses () can also be used alone, as shown in the example.
Example:
Command: echo 1 & echo 2 & echo 3
It can be written as:
(
Echo 1
Echo 2
Echo 3
)
The effect of the above two ways of writing is the same, both of which are considered to be a command line.
Note: when such multiple commands are treated as one command line, variable latency is involved if there are variables in it.
This is the end of the content of "which special symbols are commonly used in batch processing". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.