Special characters in bat and how to handle them as characters in bat (2014-02-27 21:16:55)
reproduced
Tags: bat special characters |
Category: Develop |
Special characters in bat and how to handle them as characters in bat
The actual role of special symbols in batch processing,Bat , and the role of special symbols in Windows batch processing:
@ \ \ Hide the echo of the command.
~ \ \ In for is the use of enhanced variable extension; In set, a string that uses the extended environment variable to specify the location, and a bitwise inverse in set/a.
% \ \ Uses two% contains 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, a reference to a loop variable in for, and a continuous two% to take off as 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 set/a, the bitwise XOR, in the 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 use the & command to connect the two commands; in set/a, the bitwise AND.
* \ \ \ 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 at the root 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, the previous character is matched multiple times.
() \ \ command contains or is a qualifier with precedence, such as for command to use this (), we can also be in the If,echo and other commands to see its figure;
-\ \ Range notation, such as date lookup, this character can be used in the tokens operation in the for command, and a connection of two characters in the findstr/r to indicate the matching range;-a switch that is followed by a reversal of some commands.
+ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ I use it in the Copy command, which means that a lot of files are merged into a single file, and this + character is used; in set/a is 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 set/a, it is a bitwise OR; two switches, options, or parameters are two selected in the Help document.
: \ \ Tag 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.
The \ \ Qualifier, which often uses "" to denote paths with spaces, also requires "" symbols in some commands, and in for/f the content they contain as string parsing; for/f "USEBACKQ" Indicates that they contain content that is treated as a file path and parses the contents of its file, and 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 different parameters specified by the "dir" command, and division is represented in 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, you can use "dir > lxmxn.txt" to output the results of the "dir" command to the "lxmxn.txt" text file, in findstr/r to indicate the right edge of the matching word, you need to mate 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, used for assignment of variables. For example, "set a=windows" means to assign the string "Windows" to the variable "a" and the arithmetic operation 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 their output, and in for/f ' USEBACKQ ', they are represented as string parsing.
. \ \ \ Immediately after the path or when it appears individually: A. Represents the current directory; two. Represents the previous level of the directory; when it appears in the file name in the path: the last one. Represents the separation of the primary file name from the extension file name.
&& \ \ Connect two commands and execute the && command 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, it means that the content they contain is executed as the command line and parses its output.
[] The switches, options, or parameters in the Help document are optional; in findstr/r, the character set that is specified in it is matched.
? \ \ In findstr/r indicates that an arbitrary character is matched in this position; in the path, any character is represented at this location, and immediately after/after the help document that gets the command.
! \ \ When the variable delay is enabled, use!! The variable name is expanded to represent a reference to the value of the variable, and the logical non is represented in the 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 bat and how to handle them as characters in bat