what is happening here with this %1==%* ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
taripo
Posts: 228
Joined: 01 Aug 2011 13:48

what is happening here with this %1==%* ?

#1 Post by taripo » 16 Nov 2013 11:37

I call a.bat with "abc def".
echo %1 and echo %* display the same thing.
I wonder if one contains a pair of quotation marks that the other doesn't, but echo would display them if they did. So, from the echo, they seem equal.

I want to see if they are equal.

I test with an if. But I get an error.

c:\mm>type a.bat
echo %1
echo %*
if "%1"=="%*" echo true
c:\mm>
c:\mm>
c:\mm>a "abc def"

c:\mm>echo "abc def"
"abc def"

c:\mm>echo "abc def"
"abc def"
def""==""abc was unexpected at this time.

c:\mm>if ""abc def""==""abc def"" echo true
c:\mm>

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: what is happening here with this %1==%* ?

#2 Post by ShadowThief » 16 Nov 2013 13:04

The quotes are breaking it because the quotes getting passed in are part of %1, so when you call "%1", you're really saying ""abc def "" which is the opposite of what you want to do.

I was about to recommend using %~1 and %~* but %~* is invalid, so I suggest surrounding %1 and %* with [ and ] instead.

Code: Select all

@echo off
cls

echo %1
echo %*

if [%1]==[%*] echo true

Post Reply