Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use cmd batch escape character%

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use cmd batch escape character%, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1.% is an ESCAPE character, which is usually translated as an escape character, but there are also more vivid translation names such as escape character, escape character and so on. In other words,% not only escapes and replaces the specific string associated with it, but also escapes itself. And similar to the escape character "\" in C language, double% will escape and escape to single%, and 4% will escape to double%.

2. For itself is a special command, similar to a specialized command interpreter, because its functional implementation requires the execution of multiple statements, so it must also have the function of analyzing and processing the command line (especially the command line after do). When command/cmd implements for, it naturally borrows its own command line analysis module, so for has the characteristic of two-level escape. The sentence after do in for is divided into two levels of analysis and interpretation. When the first level reads and interprets the for command line, the second level usually interprets the same command line many times when the for reads and interprets the do command.

Then, we can notice that there is no need for double% when using command-line argument variables and environment variables in do because, after the first level escape, these variables are replaced with specific immutable string constants that participate in all execution of the for loop. Alternative variables require constant dynamic changes during execution (the subcommand line after do), which naturally needs to be achieved by escaping characters, so using double% is an inevitable choice.

It is also important to note that you do not need double% to use for on the command line because the command interpreter handles the command line differently from batch processing. In earlier versions of DOS,% was not considered an escaped character on the command line, so it was not escaped and escaped, so environment variables could not be referenced directly on the command line at that time. When using for, only one% is needed for for to escape and escape. In later versions of the command interpreter, support for command-line escape (mainly for environment variables) was added, but the tradition of using single% command-line for remained.

The delayed substitution of variables in cmd is a special case, but it does not violate the above escape principle, but the environment variables in for are no longer constant.

The above is all the contents of the article "how to use cmd batch escape characters%". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report