简体   繁体   English

如何批量转义`!$`?

[英]How to escape `!$` in batch?

There are a lot of questions on StackOverflow about how to escape a given character in cmd.exe . 关于如何在cmd.exe转义给定字符,StackOverflow上存在很多问题。 However it seems that none of the solutions work in my case. 但是,似乎没有一种解决方案适用于我。

Basically, what I want to do is to set the environment variable FOO to a!$5 . 基本上,我想做的是将环境变量FOO设置为a!$5

I tried the obvious: 我尝试了明显的方法:

set FOO=a!$5

Which gives: 这使:

History expansion: set FOO=ae5

Fair enough, I guess I have to escape the ! 足够公平,我想我必须逃脱了! or the $ , or both. $或两者。 However nothing seems to work. 但是,似乎没有任何效果。

I can do: 我可以:

echo a^!
a!

And: 和:

echo a$
a$

And even: 乃至:

echo a^$
a$

But: 但:

echo a^!$
History expansion: echo a^a^$
aa$

I'm at loss figuring out what to do here. 我不知所措在这里做什么。 It seems no matter how I escape the special characters, I can't get the result I want. 看来无论我如何转义特殊字符,都无法获得想要的结果。

How can I do that ? 我怎样才能做到这一点 ?

This is apparently a bug in Clink which I have set-up on my computers. 这显然是我在计算机上设置的Clink中的错误。

I ended-up doing the boring, yet working: 我最终做的很无聊,但仍在工作:

set FOO=a!
set FOO=%FOO%$5

Which works perfectly. 哪个完美。 Sad but at least it works for anyone. 悲伤,但至少对任何人都有效。

^转义每个字符: echo a^!^$5

a!$5

Not an answer, but when I type set FOO=a!$5, that's exactly what I get. 这不是一个答案,但是当我键入set FOO = a!$ 5时,这正是我得到的。 I thought it might require a predecessor 我认为可能需要前任

Setlocal EnableDelayedExpansion Setlocal EnableDelayedExpansion

but it worked without doing that (perhaps it is my default?) Sorry I couldn't help! 但是这样做却没有效果(也许这是我的默认设置?)对不起,我无济于事!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM