Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
sri
- Posts: 6
- Joined: 05 Aug 2008 19:11
#1
Post
by sri » 14 Aug 2008 23:23
Hi
Can you please help with the below problem
I am trying to do a string compare but i am getting "The syntax of the command is incorrect"
Code: Select all
@Echo off
setlocal enabledelayedexpansion
set check=some
set fourchars=
FOR /F "TOKENS=1,2 DELIMS=_." %%a IN ("file_somenamev1.3.zip") do (set token1=%%a&set token2=%%b)
echo token1 %token1%
set fourchars=%token2:~0,4%
echo %fourchars%
if %fourchars% == %check%(
echo found
)
Thanks in advance
-
greenfinch
- Posts: 36
- Joined: 17 Jul 2008 07:37
#2
Post
by greenfinch » 17 Aug 2008 10:40
Same problem as the main topic you posted - line breaks confuse DOS/CMD processor:
Code: Select all
@Echo off
setlocal enabledelayedexpansion
set check=some
set fourchars=
FOR /F "TOKENS=1,2 DELIMS=_." %%a IN ("file_somenamev1.3.zip") do (set token1=%%a&set token2=%%b)
echo token1 %token1%
set fourchars=%token2:~0,4%
echo '%fourchars%'
if %fourchars% == %check% (echo found)
-
DosItHelp
- Expert
- Posts: 239
- Joined: 18 Feb 2006 19:54
#3
Post
by DosItHelp » 28 Aug 2008 20:57
I suggest to always put quotes around the variable expansions. It helps to remove confusion for the command interpreter, i.e. the variable name check can now contain pretty much any character without breaking the if statement. It may still break when it contains quotes, haven't tried, but other characters like ><(@^ should all be fine.
if "%fourchars%"=="%check%" (
echo found
)