简体   繁体   中英

How to escape `!$` in batch?

There are a lot of questions on StackOverflow about how to escape a given character in cmd.exe . 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 .

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.

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. I thought it might require a predecessor

Setlocal EnableDelayedExpansion

but it worked without doing that (perhaps it is my default?) Sorry I couldn't help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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