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>
what is happening here with this %1==%* ?
Moderator: DosItHelp
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: what is happening here with this %1==%* ?
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.
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