Trouble with a special character in a batch file variable

I am having trouble with a variable in a batch file. I am setting a variable with special characters, and having trouble getting them to print.

One of the two special characters is %. That one, I got to print by putting two of them in the variable. (aka % became %%) The other character is ^. I have seen that ^^ should work. But, it does not.

The (literal) string that should print is:
P%@AP[4\PZX54(P^)7

Batch file I am using:
@ECHO OFF
SET location=P%%@AP[4\PZX54(P^^)7
ECHO %location%

My output is:
P%@AP[4\PZX54(P)7

<Missing the ^>

Might I need to escape the ()'s somehow?
stakorAsked:
Who is Participating?
 
oBdACommented:
Either use four "^":
@ECHO OFF
SET location=P%%@AP[4\PZX54(P^^^^)7
ECHO %location%

Open in new window

Or use two and put part after the SET command in double quotes:
@ECHO OFF
SET "location=P%%@AP[4\PZX54(P^^)7"
ECHO %location%

Open in new window

1
 
stakorAuthor Commented:
Thank you. I would not have thought to use four of them.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.