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.


Leave a comment

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Ads I

Think About It

“What good is a ticket to the good life if you can't find the entrance?”

Ads II

Puns & Slips

“Зачем попадаться в сети, если впереди ждут увлекательные капканы?”