rsk82
rsk82

Reputation: 29387

How to correctly escape double-percent parameters, i.e. %%x to correctly show them in echo output

What I'm trying to do is to put a simple echo message on the console saying:

variable named %%x has value of 'this is text inside the variable

so command I must do must escape the percentages that belong to variable name so it doesn't evaluate. Normally the escape character for % is another %. So this works:

echo %%variable%% has value: %variable%

But this doesn't, seems that double percent variables used in for loops always evaluate:

echo %%%%x has value: %%x

Upvotes: 1

Views: 816

Answers (1)

Anders
Anders

Reputation: 101666

This is a silly hack that seems to work:

setlocal enabledelayedexpansion
set percent=%%
for %%a in (*) do (
    echo !percent!!percent!a is %%a
)

Or you can do set dblpercent=%%%% and echo !dblpercent!a...

Upvotes: 2

Related Questions