Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Comparing Strings With Embedded Spaces in Batch File

517 views
Skip to first unread message

Mark Bixby

unread,
Jul 31, 1992, 7:42:17 PM7/31/92
to
How do you compare two strings in a DOS batch file IF statement that contain
embedded spaces. I have always believed that it was done by enclosing the
strings in double quote marks. For example, I thought that the following
should work: IF "2 3" == "2 3" ECHO STRINGS MATCH
Instead of echoing STRINGS MATCH, DOS responds with Bad Command or Filename.
--
Mark Bixby Internet: ma...@spock.dis.cccd.edu
Coast Community College District 1370 Adams Avenue
District Information Services Costa Mesa, CA, USA 92626
Technical Support (714) 432-5064
"You can tune a file system, but you can't tune a fish." - tunefs(1M)

George Jetson

unread,
Aug 1, 1992, 12:41:22 PM8/1/92
to
In article <BsA1u...@spock.dis.cccd.edu> ma...@spock.dis.cccd.edu (Mark Bixby) writes:
>How do you compare two strings in a DOS batch file IF statement that contain
>embedded spaces. I have always believed that it was done by enclosing the
>strings in double quote marks. For example, I thought that the following
>should work: IF "2 3" == "2 3" ECHO STRINGS MATCH
>Instead of echoing STRINGS MATCH, DOS responds with Bad Command or Filename.

I think it has been shown that there is nothing magical about quotes in
batch file statements (internals). Note: I never used quotes much
anyway, in batch if statements - I always used the

if %1X==X ...

approach, so thus I haven't tested much of this and am only going on
what I've heard.

Anyway, the following will accomplish what you want, provided you have a
DOS grep somewhere in your file system.

echo big arbitrary string| grep "string to match" >nul
if errorlevel 1 goto not_got_it

Anyway, that's what I do...

************************************************************************
Please don't drink the battery acid, it tastes bad and will hurt you.
Also, don't bite the tyres, especially when the bike is moving.
(Our lawyers made us put this in this manual.)

- py...@quads.uchicago.edu, who is still costing the net
hundreds, if not thousands, of dollars, every time he posts -
************************************************************************

0 new messages