Nice to see you at zeyaLabs!

Never been here before? Make sure to check out the About page!

Here's a random post for you. Whatever it says, it's not what this whole blog is about. Browse the categories, click through the tags, and you'll see why. Have fun!

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

Categories

Ads I

Think About It

“Наша жизнь — театр. Не превращайте ее в цирк.”

Ads II

Puns & Slips

“Не стоило, блин, незнакомой парикмахерше говорить: "Удивите меня".”