Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
miskox
- Posts: 666
- Joined: 28 Jun 2010 03:46
#1
Post
by miskox » 12 Aug 2025 02:46
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
-
jeb
- Expert
- Posts: 1062
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#2
Post
by jeb » 13 Aug 2025 06:05
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!)