括号批处理文件中括号转义 [英] Escaping parentheses within parentheses for batch file

查看:2237
本文介绍了括号批处理文件中括号转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我要做的:

(
@echo This is some code that is
@echo Important to echo exactly as-is
@echo Even if I use parenthesis
@echo for something (like this)
)|clip

所以,具有复制到剪贴板。我曾尝试以下内容:

So having that copied into clipboard. I have tried the following:

(
@echo This is some code that is
@echo Important to echo exactly as-is
@echo Even if I use parenthesis
@echo for something ^(like this^)
)|clip

但这似乎影响到我的WANTED括号以及因为我收到一个错误。为了测试这一点,我只是做了:

But this seems to affect my WANTED parentheses as well because I receive an error. To test this, I simply done:

(
@echo This is some code that is
@echo Important to echo exactly as-is
@echo Even if I use parenthesis
@echo for something ^(like this^)
FFF
)|clip

嘿!这几乎工程,将文本复制一路的S的本。它不会复制最后一个括号,或者明明是F公司。任何想法?

Hey! This almost works, the text is copied all the way to the "s" in "this". It does not copy the last parentheses, or obviously the F's. Any ideas?

推荐答案

很明显,你需要三个插入符号有: - )

It's obvious that you need three carets there :-)

(
@echo This is some code that is
@echo Important to echo exactly as-is
@echo Even if I use parenthesis
@echo for something (like this^^^)
)|clip

为什么呢?这是一个有点棘手...

Why? That is a bit tricky...

首先解析器解析块和脱一部分此^^^)这^)中,括号在这里躲过了第一次。

First the parser parses the block and escapes the part this^^^) to this^), the parenthesis was escaped here the first time.

但是当你使用一个管道,完整的块将被翻译并转移到一个新的CMD.EXE实例。结果
C:\\ WINDOWS \\ SYSTEM32 \\ CMD.EXE / S / D / C(@回声这是一些code为...&放大器; @回声的东西(好像是这个^))

But as you used a pipe, the complete block will be translated and transfered to a new cmd.exe instance.
C:\Windows\system32\cmd.exe /S /D /c" ( @ echo This is some code is ... & @ echo for something (like this^) )"

和在新的情况下,有必要再次逃脱右括号。结果
这就是全部!

And in the new instance it is necessary again to escape the closing parenthesis.
That's all!

和获取更多信息,你可以读到类似的问题结果
<一href=\"http://stackoverflow.com/questions/8192318/why-does-delayed-expansion-fail-when-inside-a-piped-block-of-$c$c\">SO:为什么推迟扩张失败的管道块内时,code

And for more information you could read a similar question
SO: why does delayed expansion fail when inside a piped block of code

这篇关于括号批处理文件中括号转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆