Echoing Parentheses in Windows Batch Files

It’s not just about parentheses, really. It’s about almost anything that a script engine will ruthlessly interpret before executing a command: variable markers (percent signs), redirection symbols, parentheses, double quotes, ampersands…

My most common… let’s say, case, is this:

@echo off

echo Doing something (very important)...

Put this in a BATch file, run it, and you’ll end up with a message saying

... was unexpected at this time.

No, seriously? It’s great that the engine is trying to evaluate an expression within an echo, but this time I need something much more simple: round brackets embedded into a text message. Just that. Please.

Thank heavens there is a “cure”: parentheses can be escaped with a caret character.

@echo off

echo Doing something ^(very important^)...

Now we’re good:

Doing something (very important)...

Carets can be used to escape almost any special character, even a newline — to break a single command in several lines.

Share

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.