- 1 year ago
How to escape % inside double quotes in cmd?
Comment
1 / 1
To escape the percent sign (%) inside double quotes in the Windows Command Prompt (cmd), you need to use a double percent sign (%%). Here's an example:
bashecho "This is a double percent sign: %%"
When you execute this command, it will display the following output:
csharpThis is a double percent sign: %
By using two percent signs (%%), the Command Prompt treats it as a literal percent sign and does not interpret it as a variable or special character.
Note that if you're working within a batch script, you may need to escape the percent sign if it's followed by a valid variable name. In that case, you can use the caret (^) character as an escape character:
bashset myVariable=Hello
echo "This is an escaped percent sign: ^%myVariable^%"
The output of this command will be:
csharpThis is an escaped percent sign: %myVariable%
By using the caret (^) before the percent signs, you prevent the Command Prompt from treating them as variable expansion.