Page 1 of 1

Echo ( and ) within a block

Posted: 12 Aug 2025 02:46
by miskox
I have this:

Code: Select all

@echo off
set str=somestringABCDEF
(echo/)&&(echo %str%)

set str=somestring(ABCDEF)
(echo/)&&(echo %str%)
Output:

Code: Select all

c:\>a

somestringABCDEF
) was unexpected at this time.

c:\>
Ideas how to display ( and )?

ECHO/ is there just to show the problem. In reality I have a FINDSTR command and I check success/failure.

At the moment I replace '(' and ')' with '^^(' and '^^)' just for the display purposes.

Thanks.
Saso

Re: Echo ( and ) within a block

Posted: 13 Aug 2025 06:05
by jeb
Hi miskox,

simply use delayed expansion, that solves also problems with all other special characters.

Code: Select all

@echo off
setlocal enableDelayedExpansion
set str=somestringABCDEF
(echo/)&&(echo !str!)

set str=somestring(ABCDEF)
(echo/)&&(echo !str!)

Re: Echo ( and ) within a block

Posted: 14 Aug 2025 02:52
by miskox
Thanks Jeb!

Saso