Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

I don’t understand this iff error

Jul
534
10
Why does an equals sign in the filename parameter here make iff totally forget that it’s in an iff?

Sorry for lack of better phrasing here, but I just can’t get error-free output on my latest project when dealing with files that have equal signs in them.

Code:
@echo off

iff "%1" != "" .and. "%2" == "" then        
        gosub check_for_filemask
endiff              

quit

:check_for_filemask 
        echo Hello, world!
return

1735661387099.webp
 
We’re allowed to use gosubs within iffs, right?
 
The quotes remain in %1.

iff "%1" != ""

turns into

iff ""a=.txt"" != ""

which doesn't look very good. Using `a=.txt` works better.

We’re allowed to use gosubs within iffs, right?

Yes.
 
Really good observation!

This kinda makes iff a lot harder to work with than if, though.

Consider that out of 6 different situations (3 ifs * filenames with or without equals), ONLY iff fails:

Code:
@echo off

echo Try with iff:
        iff "%1" != "" then       
                gosub check_for_filemask
        endiff             

echo.
echo Try with if:
        if "%1" != "" gosub check_for_filemask

echo.
echo Try with multipe-line if ():
        if "%1" != "" (
                gosub check_for_filemask
        )    



quit

:check_for_filemask
        echo Hello, world!
return



I end up with an "endiff" error in only 1 out of 6 of those situations:

Code:
>testrf2  a.txt
Try with iff:
Hello, world!

Try with if:
Hello, world!

Try with multipe-line if ():
Hello, world!

>testrf2  a=.txt
Try with iff:
Hello, world!

Try with if:
Hello, world!

Try with multipe-line if ():
Hello, world!

>testrf2  "a.txt"
Try with iff:
Hello, world!

Try with if:
Hello, world!

Try with multipe-line if ():
Hello, world!

>testrf2  "a=.txt"
Try with iff:
Hello, world!
  Unknown command: 'endiff' 


Try with if:

Try with multipe-line if ():


Doesn’t that feel kind of inconsistent?

It doesn’t seem to be a quoting issue. It’s like this with or without quotes.
 
Back
Top