0

Suppose I have a batch file and I set a variable named PASSWORD in it like this:

set PASSWORD=Pass123%

If I then do:

echo %PASSWORD%

I notice that the % is ignored. The output is:

Pass123

I don't want the % to be ignored. I know that one way to do it is to add a % in front of it:

set PASSWORD=Pass123%%

Is there another way to do it? I tried using setlocal and quotes but it didn't work.

Alex O.
  • 1
  • 2

1 Answers1

0

Delayed Expansion off solution

It seems that quoting the entire set clause works for me

set "password=Pass123%"
echo %password%

Note: this only works with delayed expansion off. To retrieve the content of %password% when delayed expansion is on, try this:

Delayed Expansion on solution

set "password=Pass123%"
for /f "tokens=2 delims==" %%A in ('set password') do echo %%~A
Community
  • 1
  • 1