Special characters in bat and how to handle them as characters in bat

Source: Internet
Author: User
Tags echo command

batch processing, BatThe role of special symbols in Windows batch processing:

@
\ \ Hide the echo of the command.

~
\ \ In for indicates the use of an enhanced variable extension;
A string in set that represents the location specified using the extended environment variable;
The bitwise inverse is indicated in the set/a.

%
\ \ uses two% to contain a string representing the reference environment variable. For example, a%time% can be extended to the current system time;
A single% followed by a number of 0-9 indicates a reference command-line argument;
Used to denote a reference loop variable in for;
A continuous two% indicates that the execution is off to a%.

^
\ \ Cancels the escape character and closes the escape function for all escape characters . For example, to display some special characters on the screen, such as > >> | ^ Wait, you can put a ^ symbol in front of it to display this ^ after the character, ^^ is to display a ^,^| is to display a | character;
In the set/a is the bitwise XOR;
In findstr/r [] indicates that the specified character set is not matched.

&
\ \ command to connect characters. For example, if I want to execute two commands simultaneously on a single line of text, I can connect the two commands with the & command;
In SET/A is the bitwise-With.

*
\ \ represents any arbitrary character, which is what we usually call "wildcard"; for example, to find all the text files (. txt) in the C packing directory in the root directory of the C drive, you can enter the command "dir c:\*.txt";
In set/a, it is multiplication. For example "set/a x=4*2", the result is 8;
In findstr/r, it means that the previous character is matched multiple times.

()
The \ \ command contains or is a qualifier with precedence, such as the for command to use this (), we can also see it in the If,echo command;

-
\ \ Range notation, such as date lookup, which can be used in the tokens operation of the for command;
Connect two characters in findstr/r to indicate the matching range;
-a switch that is followed by the/post of certain commands to take the reverse.

+
\ \ is mainly used in the copy command to use it, indicating that many files are merged into a file, it is necessary to use the + character;
In set/a is the addition.

|
\ \ pipe character. is to put the output of the previous command as input to the next command. " dir/a/b | More "You can display the information output by the dir command on a screen-by-page basis;
In the set/a is a bitwise OR;
The two switches, options, or parameters indicated in the Help document are two selected.

:
\ \ label Locator, you can accept the label pointed to by the Goto command. For example, a "BEGIN" tag is defined in a batch file, and a "goto begin" command can be used to go to the ": Begin" transition to execute a batch command.

" "
\ \ delimiter, in the representation of a path with a space is often used "" to enclose the path, in some commands also need "" "symbol;
The content that they contain is treated as string parsing in for/f;
In for/f "USEBACKQ" means that they contain content as a file path and analyze the contents of their files;
In other cases, the content is a complete string in which >, >>, <, &, |, spaces, and so on, are no longer escaped.

/
\ \ Indicates that the following character (string) is the function switch (option) of the command. For example, "dir/s/b/a-d" means the different parameters specified by the "dir" command;
The Division is represented in the set/a.

>
\ \ command Redirect to redirect the output of the preceding command to the device behind it, and the contents of the subsequent device are overwritten. For example, "dir > Lxmxn.txt" can be used to output the results of the "dir" command to the "lxmxn.txt" text file;
The right boundary of the matched word is represented in findstr/r, which needs to be combined with the escape character \ use.

>>
\ \ Command redirection. Redirect the output of the preceding command to the device behind it, and the contents of the back device are not overwritten.

<
\ \ Takes the contents of the file that follows it as input to its preceding command.
The left boundary of the matched word is represented in findstr/r, which needs to be combined with the escape character \ use.

=
\ \ assignment symbol for assigning values to variables. For example, "set a=windows" means to assign the string "Windows" to the variable "a";
An arithmetic operation is represented in set/a, such as "set/a x=5-6*5".

\
\ \ This "\" symbol, in some cases, represents the root directory of the current path. For example, the current directory under C:\Windows\System32, then you "dir \" words, it is quite with "Dir C: \"
Represents a regular escape character in findstr/r.

‘‘
In for/f, they are used as the command line to execute and parse the output of the content they contain;
In for/f "Usebackq", the strings they contain are represented as string parsing.

.
\\
When a path is immediately behind or appears separately:
A. Represents the current directory;
Two. Indicates the previous level of the directory;
When the file name appears in the path:
The last one. Represents the separation of the primary file name from the extension file name.

&&
\ \ Connect two commands and execute && after the && command is successful;

||
\ \ Connect two commands, when | | The previous command failed before execution | | After the command.

$
\ \ In the findstr command indicates the end of a line.

``
In for/f, the content that they contain is executed as the command line and parsed by its output.

[]
The switches, options, or parameters that are represented in the Help document are optional;
In Findstr/r, the character set that is specified in the match.

?
\ \ In findstr/r to match an arbitrary character in this position;
? In the path indicates that any character is to be fitted in this position;
A help document that immediately follows/after the GET command.

!
\ \ When the variable delay is enabled, use!! The variable name is expanded to represent a reference to the value of the variable;
Represents a logical non in set/a. For example set/a a=!0, at this point A is a representation of logic 1.

The above is the emphasis on a half-day special characters, but if we need to pass them as a string parameter when the what to do that, needless to say, the first consideration is to add "" and then escaped into character processing, but my practice tells me "\>", "\<", "\@", "\|" Do not realize the function you want, is a headache when the idea of a good way, is to take this special character in the ASCII table in the decimal number to replace the damned things, and then the interpretation of the ASCII 10 binary number converted to ASCII character processing.

Finally, it is possible to verify the effect, so that the problem of avoiding the conflict of keywords in bat is an effective solution. Guys can try.

Special characters in the

bat and how to handle them as characters in the bat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.